https://issues.dlang.org/show_bug.cgi?id=22889
Issue ID: 22889 Summary: Selective import shadows local variable Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nob...@puremagic.com Reporter: snarwin+bugzi...@gmail.com As of DMD 2.099.0, the following program compiles and runs without error: --- lib.d int x = 1; --- main.d void main() { int x = 2; { import lib : x; assert(x == 1); } } --- The language spec [1] states that name lookup proceeds in two phases: first, symbols in the current module and inherited scopes are considered; second, imported symbols are considered. It is not stated explicitly whether selectively-imported symbols are considered in phase 1 or phase 2. If selectively-imported symbols are considered in phase 1, the above program should yield a compile-time error, because symbols are not permitted to shadow other symbols declared in the same function. If selectively-imported symbols are considered in phase 2, the above program should yield a runtime error, because the local `x` should hide the imported `x`. Either way, the observed behavior cannot possibly be correct. [1] https://dlang.org/spec/module.html#name_lookup --