Bug 19464 – typeof immutable fields order dependent
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-12-04T13:56:21Z
Last change time
2018-12-12T09:32:22Z
Assigned to
No Owner
Creator
Dennis
Comments
Comment #0 by dkorpel — 2018-12-04T13:56:21Z
When declaring an immutable field using typeof() on another immutable field, the field in typeof() has to be declared above or the new one won't be immutable.
Code:
```
typeof(a0) b0 = 3;
immutable int a0 = 4;
pragma(msg, typeof(b0));
immutable int a1 = 4;
typeof(a1) b1 = 3;
pragma(msg, typeof(b1));
```
Expected:
immutable(int)
immutable(int)
Actual:
int
immutable(int)
Comment #1 by simen.kjaras — 2018-12-04T14:07:15Z
This only occurs for basic types - structs, classes, arrays, assoc arrays, pointers, aliases, etc, don't exhibit this behavior.
Comment #2 by razvan.nitu1305 — 2018-12-11T14:48:54Z