www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12385] New: You can modify some immutable values in enums.

https://d.puremagic.com/issues/show_bug.cgi?id=12385

           Summary: You can modify some immutable values in enums.
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: devw0rp gmail.com


--- Comment #0 from w0rp <devw0rp gmail.com> 2014-03-16 18:24:22 PDT ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 16 2014