From 0c9374cec813f8b29483bebd5a659be55958c299 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Tue, 13 Sep 2016 07:32:11 +0200 Subject: [PATCH] fix Issue 16460 - ICE for package visibility check in function literal - fixed by skipping symbol-less scopes when establishing scope for FuncDeclaration - symbol-less scopes like Scope.startCTFE and FuncExp scopes don't require a symbol table (and thus don't create a scopesym) --- src/func.d | 10 +++++++++- test/compilable/imports/imp16460.d | 3 +++ test/compilable/test16460.d | 13 +++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/compilable/imports/imp16460.d create mode 100644 test/compilable/test16460.d diff --git a/src/func.d b/src/func.d index 3994772ce6d0..e8a33011596b 100644 --- a/src/func.d +++ b/src/func.d @@ -1397,7 +1397,15 @@ public: localsymtab = new DsymbolTable(); // Establish function scope auto ss = new ScopeDsymbol(); - ss.parent = sc.scopesym; + // find enclosing scope symbol, might skip symbol-less CTFE and/or FuncExp scopes + for (auto scx = sc; ; scx = scx.enclosing) + { + if (scx.scopesym) + { + ss.parent = scx.scopesym; + break; + } + } Scope* sc2 = sc.push(ss); sc2.func = this; sc2.parent = this; diff --git a/test/compilable/imports/imp16460.d b/test/compilable/imports/imp16460.d new file mode 100644 index 000000000000..f729004e9c06 --- /dev/null +++ b/test/compilable/imports/imp16460.d @@ -0,0 +1,3 @@ +module imports.imp16460; + +package enum val = 0; diff --git a/test/compilable/test16460.d b/test/compilable/test16460.d new file mode 100644 index 000000000000..868e7ecec4a5 --- /dev/null +++ b/test/compilable/test16460.d @@ -0,0 +1,13 @@ +module imports.test16460; + +void bug() +{ + auto d1 = (){ + import imports.imp16460; + return val; + }; + enum d2 = (){ + import imports.imp16460; + return val; + }; +}