www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15612] New: Break immutability with default initialisers

https://issues.dlang.org/show_bug.cgi?id=15612

          Issue ID: 15612
           Summary: Break immutability with default initialisers
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: john.loughran.colvin gmail.com

void main()
{
    immutable S s0;
    S s1;
    assert(s0.c.a == 42);
    s1.c.a = -42;
    assert(s0.c.a == 42); //FAILS!
}

struct S
{
    C c = new C(42);
}

class C
{
    int a;
    this(int a)
    {
        this.a = a;
    }
}

--
Jan 26