Bug 3948 – Array literal assign to array of different length

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-03-13T04:45:00Z
Last change time
2014-02-15T02:42:35Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-03-13T04:45:14Z
The compiler accepts this with no errors, but this is wrong code: enum int[1] a = [0, 1]; void main() {}
Comment #1 by bearophile_hugs — 2010-03-13T15:04:09Z
See also related bug 3949 . Another case, this compiles with no errors, but it's bug-prone: const real x = 1.2; real[4][4] M2 = [[0, 0, 1, x], [0, 0, 0, 1]]; void main() {} ---------------- This doesn't compile: const real x = 1.2; real[2][4] M2 = [[0, 0, 1, x], [0, 0, 0, 1]]; void main() {} But the error message is bad and can be improved: test.d(3): Error: cannot implicitly convert expression ([0,0,0,1]) of type int[] to real[2u] ---------------- This code: real x = 1.2; real[4][4] M2 = [[1, 0, 0, x], [0, 1, 0, x], [0, 0, 1, x], [0, 0, 0, 1]]; void main() {} Produces the following errors (I don't know if this is correct): bug1.d(5): Error: non-constant expression x bug1.d(5): Error: non-constant expression x bug1.d(5): Error: non-constant expression x
Comment #2 by bearophile_hugs — 2010-03-17T12:45:03Z
See related bug 3849 too.
Comment #3 by clugdbug — 2010-05-12T12:32:24Z
Fixed DMD2.045 (same root cause as bug 3974). Note that the final case in comment 1, the unhelpful line number is bug 3394. The first case in comment 1 is a duplicate of bug 3849. The other cases are fixed.