Summary: Immutable class may be changed when inherits from
                    mutable parent
           Product: D
           Version: 2.039
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Tomasz SowiƄski <> 2010-01-20 12:44:48 
PST ---
This merrily compiles:

class Zmienna {
    int a;
    this(int a) {
        this.a = a;

immutable class Stala : Zmienna {
    this(int a) {

void main() {
    auto st = new Stala(5);
    Zmienna zm = st;
    zm.a = 666;
//  st.a = 666; // fails
    assert (st.a == 666);

The above shows that an immutable class shouldn't be allowed to derive from
mutable classes. Unfortunately it won't work because Object is not (and can't
be) immutable. Not sure how to bite this one, perhaps make an opt out that says
mutable parents with no fields are OK? Or an exception only for Object?

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to