Created attachment 382
Fix the problem (dmd 2.030)
DMD dies without any error message compiling this valid code:
--------------------
immutable int[2] array = [ 42 ];
enum e = array[1];
--------------------
The array initializer in this code contains one element. In this case
ArrayInitializer::toExpression() wrongly generates an ArrayLiteralExp
of one element, not two elements (notice the int[2]). Then DMD references
missing second element, and dies. The patch fixes this problem.
And DMD rejects this valid code:
--------------------
immutable int[1] array = [ 0: 42 ];
enum e = array[0];
--------------------
test.d(1): Error: array initializers as expressions are not allowed
test.d(1): Error: array initializers as expressions are not allowed
test.d(1): Error: array initializers as expressions are not allowed
test.d(1): Error: array initializers as expressions are not allowed
--------------------
ArrayInitializer::toExpression() does not implement support for array
index in static array initializers. The patch also implements it.
Comment #1 by rsinfu — 2009-06-04T10:06:13Z
Created attachment 390
Additional patch: fix segfault on fwdref
ArrayInitializer will cause a segfault when it's forward referenced. Please apply this patch in addition to the first patch.