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