Dumping the AST of static foreach(enum i; 0..3) mixin("int a" ~ i.stringof ~ " = 1;"); with "dmd -c -vcg-ast test.d" yields: import object; mixin("int a" ~ i.stringof ~ " = 1;"); I'd rather expect: import object; int a0 = 1; int a1 = 1; int a2 = 1;
Ah yes. -vcg-ast has not been updated for static foreach I think. ..... It seems like it has been already though .... Maybe the created AST-Nodes are non-persistent .... which would make static foreach quite volatile after all
Dumping the AST of: static if(true){ enum a = 1; } with "dmd -c -vcg-ast test.d" yields: import object; static if (true) { enum int a = 1; } Therefore, shouldn't the expected output be: static foreach(enum i; 0..3) { mixin("int a" ~ i.stringof ~ " = 1;"); } ?
If it correctly represents the original code, it should be ok, too. I expected the dump to have expanded all compile time transformations and lowerings, but obviously it does not. I just tried -vcg-ast on: mixin("int a" ~ 1.stringof ~ " = 1;"); and it yields import object; mixin("int a1" ~ " = 1;"); so it's at some random intermediate step.
https://github.com/dlang/dmd/pull/7126
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/4317772a132873b9b0cf527312fe8b35e8b11265 fix Issue 17814 - bad output of "static foreach" with -vcg-ast https://github.com/dlang/dmd/commit/591c7bbfae7fa0781222dcb15a91a40214fc2976 Merge pull request #7126 from tgehr/fix17814 fix Issue 17814 - bad output of "static foreach" with -vcg-ast
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/4317772a132873b9b0cf527312fe8b35e8b11265 fix Issue 17814 - bad output of "static foreach" with -vcg-ast https://github.com/dlang/dmd/commit/591c7bbfae7fa0781222dcb15a91a40214fc2976 Merge pull request #7126 from tgehr/fix17814