← Back to index
|
Original Bugzilla link
Bug 5949 – Mutable enum matrix rows
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-05-07T16:08:46Z
Last change time
2020-09-06T22:17:59Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0
by bearophile_hugs — 2011-05-07T16:08:46Z
This D2 code compiles and runs with no errors (DMD 2.053beta), but it's wrong: void main() { enum int[][] data = [[1]]; foreach (a; data) a[0]++; assert(data[0][0] == 1); foreach (ref a; data) a[0]++; assert(data[0][0] == 1); }
Comment #1
by lt.infiltrator — 2014-03-19T18:02:42Z
Issue still exists as of v2.065.
Comment #2
by pro.mathias.lang — 2020-09-06T22:17:59Z
The `enum` gives a literal, so the compiler is correct here. The code works as expected. Using `[static] immutable` will give the desired error.