Code:

union A {
    immutable int f;
}

union B {
    immutable int f;
    int e;
}

void main() {
    A a = A(1);
    //a = A(2); // a.f is immutable, fails to compile as expected
        
    B b = B(1);
    b = B(2); // compiles!!!
}

It turns out that if the union contains at least one mutable member, then the entire union is considered to be mutable. It's logical, but does it meet the specs? I couldn't find description of this behavior.

Reply via email to