From 801dbf7bb83cf11aa206f6a1c9bc609c0ae72f47 Mon Sep 17 00:00:00 2001 From: k-hara Date: Sun, 25 Mar 2012 03:56:20 +0900 Subject: [PATCH] fix Issue 7757 - Inout function with lazy inout parameter doesn't compile --- src/delegatize.c | 5 ++++- src/expression.c | 5 ++++- src/mtype.c | 7 +++++-- test/runnable/testconst.d | 29 +++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/delegatize.c b/src/delegatize.c index a4d371527f0a..b08892f1ff3a 100644 --- a/src/delegatize.c +++ b/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; diff --git a/src/expression.c b/src/expression.c index d4e892b65511..d6937065512d 100644 --- a/src/expression.c +++ b/src/expression.c @@ -7444,7 +7444,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); } diff --git a/src/mtype.c b/src/mtype.c index 1e64432d6a78..0df6027113e0 100644 --- a/src/mtype.c +++ b/src/mtype.c @@ -1868,7 +1868,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); @@ -4418,8 +4421,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 diff --git a/test/runnable/testconst.d b/test/runnable/testconst.d index 690c3d4cfd8c..393de54487ca 100644 --- a/test/runnable/testconst.d +++ b/test/runnable/testconst.d @@ -2575,6 +2575,34 @@ void test7669() 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() @@ -2687,6 +2715,7 @@ int main() test7554(); test7518(); test7669(); + test7757(); printf("Success\n"); return 0;