Bug 7077 – (D1 only) mixin statements can invade the enclosing scope

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
All
Creation time
2011-12-07T05:16:00Z
Last change time
2013-11-29T03:41:33Z
Keywords
accepts-invalid, pull, rejects-valid
Assigned to
nobody
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2011-12-07T05:16:20Z
compiles, should not compile: void main(){ if(0) mixin(q{auto x = 2;}); writeln(x); } does not compile, should compile: void main(){ if(0) mixin(q{auto x = 2;}); auto x = 1; } The workaround is to put {...} around the mixin statement. (For comparison, this does not compile: void main(){ if(0) auto x = 2; writeln(x); } And this does compile: void main(){ if(0) auto x = 2; auto x = 1; })
Comment #1 by hsteoh — 2013-07-28T16:15:08Z
I thought the whole point of mixins is to insert declarations into the enclosing scope? Otherwise it would break mixins that insert, e.g., member declarations into classes.
Comment #2 by yebblies — 2013-07-29T02:16:31Z
Nah, `mixin("X")` should behave as close as possible to `X`, and here it is being injected into the wrong scope. The bug is actually IfStatement not creating a proper scope for the if-body. https://github.com/D-Programming-Language/dmd/pull/2402
Comment #3 by github-bugzilla — 2013-07-29T04:43:18Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1b3b8611661dd86190dca151bc8106fc694c3ac1 Fix Issue 7077 - mixin statements can invade the enclosing scope The if body should always be inside its own scope https://github.com/D-Programming-Language/dmd/commit/f1c47fbbb2688888d1c4f001d8d338a885704bfe Merge pull request #2402 from yebblies/issue7077 Fix Issue 7077 - mixin statements can invade the enclosing scope
Comment #4 by yebblies — 2013-07-29T04:46:32Z
Still exists in D1
Comment #5 by yebblies — 2013-11-29T03:41:33Z
Was fixed for D2, D1 is no longer supported.