Skip to content

Commit

Permalink
Merge pull request #836 from 9rnsr/fix7757
Browse files Browse the repository at this point in the history
Issue 7757 - Inout function with lazy inout parameter doesn't compile
  • Loading branch information
WalterBright committed Mar 27, 2012
2 parents 28c0da0 + 801dbf7 commit e74a26a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/delegatize.c
Expand Up @@ -34,7 +34,10 @@ int lambdaCheckForNestedRef(Expression *e, void *param);
Expression *Expression::toDelegate(Scope *sc, Type *t) Expression *Expression::toDelegate(Scope *sc, Type *t)
{ {
//printf("Expression::toDelegate(t = %s) %s\n", t->toChars(), toChars()); //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 = FuncLiteralDeclaration *fld =
new FuncLiteralDeclaration(loc, loc, tf, TOKdelegate, NULL); new FuncLiteralDeclaration(loc, loc, tf, TOKdelegate, NULL);
Expression *e; Expression *e;
Expand Down
5 changes: 4 additions & 1 deletion src/expression.c
Expand Up @@ -7448,7 +7448,10 @@ Expression *CallExp::semantic(Scope *sc)
if (ve->var->storage_class & STClazy) if (ve->var->storage_class & STClazy)
{ {
// lazy paramaters can be called without violating purity and safety // 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); TypeDelegate *t = new TypeDelegate(tf);
ve->type = t->semantic(loc, sc); ve->type = t->semantic(loc, sc);
} }
Expand Down
7 changes: 5 additions & 2 deletions src/mtype.c
Expand Up @@ -1882,7 +1882,10 @@ Type *Type::substWildTo(unsigned mod)
else if (ty == Tsarray) else if (ty == Tsarray)
t = new TypeSArray(t, ((TypeSArray *)this)->dim->syntaxCopy()); t = new TypeSArray(t, ((TypeSArray *)this)->dim->syntaxCopy());
else if (ty == Taarray) else if (ty == Taarray)
{
t = new TypeAArray(t, ((TypeAArray *)this)->index->syntaxCopy()); t = new TypeAArray(t, ((TypeAArray *)this)->index->syntaxCopy());
((TypeAArray *)t)->sc = ((TypeAArray *)this)->sc; // duplicate scope
}
else else
assert(0); assert(0);


Expand Down Expand Up @@ -4432,8 +4435,8 @@ StructDeclaration *TypeAArray::getImpl()
* which has Tident's instead of real types. * which has Tident's instead of real types.
*/ */
Objects *tiargs = new Objects(); Objects *tiargs = new Objects();
tiargs->push(index); tiargs->push(index->substWildTo(MODconst)); // hack for bug7757
tiargs->push(next); tiargs->push(next ->substWildTo(MODconst)); // hack for bug7757


// Create AssociativeArray!(index, next) // Create AssociativeArray!(index, next)
#if 1 #if 1
Expand Down
29 changes: 29 additions & 0 deletions test/runnable/testconst.d
Expand Up @@ -2575,6 +2575,34 @@ void test7669()
static assert(is(typeof( id7669((shared(int)[3]).init)) == shared(int)[3])); static assert(is(typeof( id7669((shared(int)[3]).init)) == shared(int)[3]));
} }


/************************************/
// 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() int main()
Expand Down Expand Up @@ -2687,6 +2715,7 @@ int main()
test7554(); test7554();
test7518(); test7518();
test7669(); test7669();
test7757();


printf("Success\n"); printf("Success\n");
return 0; return 0;
Expand Down

0 comments on commit e74a26a

Please sign in to comment.