Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #836 from 9rnsr/fix7757

Issue 7757 - Inout function with lazy inout parameter doesn't compile
  • Loading branch information...
commit e74a26ad05629d72d353552ef144ac69c3e9994a 2 parents 28c0da0 + 801dbf7
@WalterBright WalterBright authored
View
5 src/delegatize.c
@@ -34,7 +34,10 @@ int lambdaCheckForNestedRef(Expression *e, void *param);
Expression *Expression::toDelegate(Scope *sc, Type *t)
{
//printf("Expression::toDelegate(t = %s) %s\n", t->toChars(), toChars());
- TypeFunction *tf = new TypeFunction(NULL, t, 0, LINKd);
+ Type *tw = t->semantic(loc, sc);
+ Type *tc = t->substWildTo(MODconst)->semantic(loc, sc);
+ TypeFunction *tf = new TypeFunction(NULL, tc, 0, LINKd);
+ (tf = (TypeFunction *)tf->semantic(loc, sc))->next = tw; // hack for bug7757
FuncLiteralDeclaration *fld =
new FuncLiteralDeclaration(loc, loc, tf, TOKdelegate, NULL);
Expression *e;
View
5 src/expression.c
@@ -7448,7 +7448,10 @@ Expression *CallExp::semantic(Scope *sc)
if (ve->var->storage_class & STClazy)
{
// lazy paramaters can be called without violating purity and safety
- TypeFunction *tf = new TypeFunction(NULL, ve->var->type, 0, LINKd, STCsafe | STCpure);
+ Type *tw = ve->var->type;
+ Type *tc = ve->var->type->substWildTo(MODconst);
+ TypeFunction *tf = new TypeFunction(NULL, tc, 0, LINKd, STCsafe | STCpure);
+ (tf = (TypeFunction *)tf->semantic(loc, sc))->next = tw; // hack for bug7757
TypeDelegate *t = new TypeDelegate(tf);
ve->type = t->semantic(loc, sc);
}
View
7 src/mtype.c
@@ -1882,7 +1882,10 @@ Type *Type::substWildTo(unsigned mod)
else if (ty == Tsarray)
t = new TypeSArray(t, ((TypeSArray *)this)->dim->syntaxCopy());
else if (ty == Taarray)
+ {
t = new TypeAArray(t, ((TypeAArray *)this)->index->syntaxCopy());
+ ((TypeAArray *)t)->sc = ((TypeAArray *)this)->sc; // duplicate scope
+ }
else
assert(0);
@@ -4432,8 +4435,8 @@ StructDeclaration *TypeAArray::getImpl()
* which has Tident's instead of real types.
*/
Objects *tiargs = new Objects();
- tiargs->push(index);
- tiargs->push(next);
+ tiargs->push(index->substWildTo(MODconst)); // hack for bug7757
+ tiargs->push(next ->substWildTo(MODconst)); // hack for bug7757
// Create AssociativeArray!(index, next)
#if 1
View
29 test/runnable/testconst.d
@@ -2576,6 +2576,34 @@ void test7669()
}
/************************************/
+// 7757
+
+inout(int) foo7757a(int x, lazy inout(int) def) { return def; }
+inout(int)[] foo7757b(int x, lazy inout(int)[] def) { return def; }
+inout(int)[int] foo7757c(int x, lazy inout(int)[int] def) { return def; }
+
+inout(T) bar7757a(T)(T x, lazy inout(T) def) { return def; }
+inout(T)[] bar7757b(T)(T x, lazy inout(T)[] def) { return def; }
+inout(T)[T] bar7757c(T)(T x, lazy inout(T)[T] def) { return def; }
+
+void test7757()
+{
+ int mx1 = foo7757a(1,2);
+ const(int) cx1 = foo7757a(1,2);
+ int [] ma1 = foo7757b(1,[2]);
+ const(int)[] ca1 = foo7757b(1,[2]);
+ int [int] maa1 = foo7757c(1,[2:3]);
+ const(int)[int] caa1 = foo7757c(1,[2:3]);
+
+ int mx2 = bar7757a(1,2);
+ const(int) cx2 = bar7757a(1,2);
+ int [] ma2 = bar7757b(1,[2]);
+ const(int)[] ca2 = bar7757b(1,[2]);
+ int [int] maa2 = bar7757c(1,[2:3]);
+ const(int)[int] caa2 = bar7757c(1,[2:3]);
+}
+
+/************************************/
int main()
{
@@ -2687,6 +2715,7 @@ int main()
test7554();
test7518();
test7669();
+ test7757();
printf("Success\n");
return 0;
Please sign in to comment.
Something went wrong with that request. Please try again.