Skip to content

Commit

Permalink
Merge pull request #10764 from atilaneves/fix-20362
Browse files Browse the repository at this point in the history
Fix issue 20362 - always infer scope for lambdas
merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Feb 6, 2020
2 parents 870e208 + ac32a33 commit bb1981f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/dmd/semantic3.d
Expand Up @@ -456,8 +456,14 @@ private extern(C++) final class Semantic3Visitor : Visitor
stc |= STC.scope_;
}
}
if (funcdecl.flags & FUNCFLAG.inferScope && !(fparam.storageClass & STC.scope_))

// infer scope for lambdas even without -preview=dip1000
// See https://issues.dlang.org/show_bug.cgi?id=20362
const isLambda = funcdecl.isFuncLiteralDeclaration;

if ((funcdecl.flags & FUNCFLAG.inferScope || isLambda) && !(fparam.storageClass & STC.scope_))
stc |= STC.maybescope;

stc |= fparam.storageClass & (STC.in_ | STC.out_ | STC.ref_ | STC.return_ | STC.scope_ | STC.lazy_ | STC.final_ | STC.TYPECTOR | STC.nodtor);
v.storage_class = stc;
v.dsymbolSemantic(sc2);
Expand Down
8 changes: 8 additions & 0 deletions test/compilable/issue20362.d
@@ -0,0 +1,8 @@
void main() {
string str;
stringify((chars) {str ~= chars; });
}

void stringify(scope void delegate(scope const char[]) sink) {
sink("oops");
}

0 comments on commit bb1981f

Please sign in to comment.