From d6b17f7ae39aada48e509b8f587e17fd72e274ea Mon Sep 17 00:00:00 2001 From: k-hara Date: Wed, 29 Jul 2015 19:34:49 +0900 Subject: [PATCH] fix Issue 14846 - Insufficient context deduction with implicit nested lambda --- src/declaration.c | 2 ++ src/expression.c | 15 +++++++++++---- test/runnable/nested.d | 31 +++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/declaration.c b/src/declaration.c index e61ae76fa606..a044ee8fc547 100644 --- a/src/declaration.c +++ b/src/declaration.c @@ -51,6 +51,8 @@ bool checkFrameAccess(Loc loc, Scope *sc, AggregateDeclaration *ad, size_t iStar { if (!fd->isThis() && !fd->isNested()) break; + if (FuncLiteralDeclaration *fld = fd->isFuncLiteralDeclaration()) + fld->tok = TOKdelegate; } if (AggregateDeclaration *ad2 = s->isAggregateDeclaration()) { diff --git a/src/expression.c b/src/expression.c index bdf25fbf8053..489bdfca17ab 100644 --- a/src/expression.c +++ b/src/expression.c @@ -4385,9 +4385,6 @@ Expression *StructLiteralExp::semantic(Scope *sc) if (!sd->fit(loc, sc, elements, stype)) return new ErrorExp(); - if (checkFrameAccess(loc, sc, sd, elements->dim)) - return new ErrorExp(); - /* Fill out remainder of elements[] with default initializers for fields[] */ if (!sd->fill(loc, elements, false)) @@ -4399,6 +4396,10 @@ Expression *StructLiteralExp::semantic(Scope *sc) global.increaseErrorCount(); return new ErrorExp(); } + + if (checkFrameAccess(loc, sc, sd, elements->dim)) + return new ErrorExp(); + type = stype ? stype : sd->type; return this; } @@ -5070,14 +5071,18 @@ Expression *NewExp::semantic(Scope *sc) member = f->isCtorDeclaration(); assert(member); + + if (checkFrameAccess(loc, sc, sd, sd->fields.dim)) + return new ErrorExp(); } else { if (!sd->fit(loc, sc, arguments, tb)) return new ErrorExp(); - if (!sd->fill(loc, arguments, false)) return new ErrorExp(); + if (checkFrameAccess(loc, sc, sd, arguments ? arguments->dim : 0)) + return new ErrorExp(); } type = type->pointerTo(); @@ -8447,6 +8452,8 @@ Expression *CallExp::semantic(Scope *sc) StructLiteralExp *sle = new StructLiteralExp(loc, sd, NULL, e1->type); if (!sd->fill(loc, sle->elements, true)) return new ErrorExp(); + if (checkFrameAccess(loc, sc, sd, sle->elements->dim)) + return new ErrorExp(); // Bugzilla 14556: Set concrete type to avoid further redundant semantic(). sle->type = e1->type; diff --git a/test/runnable/nested.d b/test/runnable/nested.d index 8a5eb9f975ea..53da653f2aa5 100644 --- a/test/runnable/nested.d +++ b/test/runnable/nested.d @@ -2455,6 +2455,36 @@ void test14398() assert(outer == 42); // inner is copied successfully } +/*******************************************/ +// 14846 + +void foo14846(Dg)(scope Dg code) +{ + static assert(is(Dg == delegate)); + code(); +} + +void test14846() +{ + int x; + + struct S + { + this(int n) { x = n; } + ~this() { x = 99; } + } + + foo14846({ S s; }); + foo14846({ S s = S(); }); + foo14846({ S s = S(1); }); + foo14846({ S[3] s; }); + + foo14846({ S* p = new S(); }); + foo14846({ S* p = new S(1); }); + foo14846({ S[] a = [S()]; }); + foo14846({ S[] a = [S(1)]; }); +} + /*******************************************/ int main() @@ -2546,6 +2576,7 @@ int main() test12234(); test13861(); test14398(); + test14846(); printf("Success\n"); return 0;