On 10/21/2015 02:54 PM, Don wrote:

Fundamentally the problem is that literals of mutable reference types do
not make sense.

I think considering "[x,y,z]" a 'literal' is a problem, but why is it the problem here? It is not really treated like a literal in this context. This has the same issue:

class D{ int x=0; }
class C{ auto x=new D; }

void main(){
    auto c1=new C;
    auto c2=new immutable(C);
    assert(c2.x.x==0);
    c1.x.x=1;
    assert(c2.x.x==1);
}


This is why I argued (before TDPL came out), that an
explicit .dup should be required, rather than allowing the compiler to
secretly add one automatically. Implicit conversion of an array literal
to mutable is ridiculous IMHO.

Where does the "implicit conversion to mutable" happen here?:

class C{ int x; }

void main(){
    auto c=new C;
    auto a=[c];
}

Reply via email to