Bug 12385 – Enum member should not be modifiable when the member is immutable
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-16T18:24:22Z
Last change time
2017-12-18T22:57:37Z
Keywords
pull
Assigned to
Andrej Mitrovic
Creator
w0rp
Comments
Comment #0 by devw0rp — 2014-03-16T18:24:22Z
I was just helping someone in IRC with something when I ran into this. I'm
not exactly sure what caused it, but the bug is there.
---
protected class BundledState {
protected string m_State;
int x = 3;
public this(string state) immutable {
m_State = state;
}
}
enum States : immutable(BundledState) {
unbundled = new immutable BundledState("bla"),
}
immutable BundledState foo = new immutable BundledState("bla");
void main(string[] argv) {
States.unbundled.x = 6; // Modifies x.
foo.x = 5; // Error, as expected.
}
---
So you can modify the immutable data 'unbundled' which is in an enum, but not the module scope 'foo'. You shouldn't be able to modify either.