diff --git a/src/dmd/func.d b/src/dmd/func.d index c30c81f9276c..232d2f01ea13 100644 --- a/src/dmd/func.d +++ b/src/dmd/func.d @@ -3305,6 +3305,9 @@ extern (C++) final class FuncLiteralDeclaration : FuncDeclaration this.ident = id ? id : Id.empty; this.tok = tok; this.fes = fes; + // Always infer scope for function literals + // See https://issues.dlang.org/show_bug.cgi?id=20362 + this.flags |= FUNCFLAG.inferScope; //printf("FuncLiteralDeclaration() id = '%s', type = '%s'\n", this.ident.toChars(), type.toChars()); } diff --git a/src/dmd/semantic3.d b/src/dmd/semantic3.d index 3e594aa341ae..7418da7dad41 100644 --- a/src/dmd/semantic3.d +++ b/src/dmd/semantic3.d @@ -457,11 +457,7 @@ private extern(C++) final class Semantic3Visitor : Visitor } } - // 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_)) + if ((funcdecl.flags & FUNCFLAG.inferScope) && !(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);