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.
Comment #1 by slavo5150 — 2017-11-21T13:45:27Z
Comment #2 by github-bugzilla — 2017-12-06T10:13:44Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/334f853e8371fdab46875bf3316ba78a7c237578 Fix Issue 12385 - Enum member should not be modifiable when the member is immutable https://github.com/dlang/dmd/commit/0da1457a01b9e1e7188383d86cd0ecbd5fc86fec Merge pull request #7348 from JinShil/fix_12385 Fix Issue 12385 - Enum member should not be modifiable when the member is immutable merged-on-behalf-of: Walter Bright <[email protected]>
Comment #3 by github-bugzilla — 2017-12-18T22:57:37Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/334f853e8371fdab46875bf3316ba78a7c237578 Fix Issue 12385 - Enum member should not be modifiable when the member is immutable https://github.com/dlang/dmd/commit/0da1457a01b9e1e7188383d86cd0ecbd5fc86fec Merge pull request #7348 from JinShil/fix_12385