Created attachment 1337
Example Code - "dmd main.d"
When a struct enum is defined like this, it's values cannot be read at compile
time.
enum Point3D point = {x:1, y:1, z:1};
int testArray[point.x][point.y][point.z]; // z Cannot be read at
compile time (will error 6 times)
Working (well, technically not working) code in attachment. Tested for both 32
bit and 64 bit on a Linux system.
Comment #1 by jbinero — 2014-03-06T13:54:39Z
(In reply to comment #0)
> Created an attachment (id=1337) [details]
> Example Code - "dmd main.d"
>
> When a struct enum is defined like this, it's values cannot be read at compile
> time.
> enum Point3D point = {x:1, y:1, z:1};
> int testArray[point.x][point.y][point.z]; // z Cannot be read at
> compile time (will error 6 times)
>
> Working (well, technically not working) code in attachment. Tested for both 32
> bit and 64 bit on a Linux system.
Probably not important, but it errors 5 times and not 6. With adding and removing to the code I have found inconsistency in how many times it errors, and what variable it picks though.
Comment #2 by dlang-bugzilla — 2014-03-06T15:28:20Z
Looks like the compiler parses the array declaration as an associative array (and conservatively assumes that "point.x" is a type), then when it realizes it is in fact a static array, it does not reparse the whole "point.x" expression correctly (it just looks at the last symbol, x). Making it clear that it is an expression, e.g. adding "+0", also fixes compilation.
Fixing this is not trivial as the expression that the compiler sees in the array index is not saved. I think the correct fix would be to switch the parsing order: Assume that the array "index" is an expression, then, if it resolves to a type, reinterpret the whole thing as an associative array.