← Back to index
|
Original Bugzilla link
Bug 16354 – CTFE static foreach doesn't work with mixin import
Status
RESOLVED
Resolution
INVALID
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-08-05T12:36:00Z
Last change time
2016-08-05T13:17:43Z
Assigned to
nobody
Creator
greensunny12
Comments
Comment #0
by greensunny12 — 2016-08-05T12:36:18Z
Using static foreach with mixin imports doesn't seem to work whereas it works with the CTFE foreach loop; >foo.d void main() { import std.meta : AliasSeq; alias mods = AliasSeq!("test1"); foreach (mod; mods) mixin("import bar : " ~ mod ~ " = bar_fun;"); test1(); } >bar.d void bar_fun() { import std.stdio; writeln("works"); } One gets: > foo.d(9): Error: undefined identifier 'test1' However this does work ("manual loop unrolling") fine: >foo.d void main() { import std.meta : AliasSeq; alias mods = AliasSeq!("test1"); mixin("import bar : " ~ mods[0] ~ " = bar_fun;"); test1(); }
Comment #1
by mathias.lang — 2016-08-05T12:51:25Z
Foreach creates a scope. And you are referencing `test1` from outside of that scope.
Comment #2
by greensunny12 — 2016-08-05T13:17:43Z
> Foreach creates a scope. And you are referencing `test1` from outside of that scope. Oh damn. Sorry about the noise :/