Bug 17814 – bad output of "static foreach" with -vcg-ast
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2017-09-07T07:46:13Z
Last change time
2017-10-01T20:41:04Z
Assigned to
No Owner
Creator
Rainer Schuetze
Comments
Comment #0 by r.sagitario — 2017-09-07T07:46:13Z
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;
Comment #1 by uplink.coder — 2017-09-07T11:02:24Z
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
Comment #2 by timon.gehr — 2017-09-07T19:59:26Z
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;");
}
?
Comment #3 by r.sagitario — 2017-09-07T20:15:31Z
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.