Summary: dmd accepts mutable AA key types for objects
--- Comment #0 from Jonathan M Davis <jmdavisp...@gmx.com> 2012-09-17 13:29:18
I would have thought that this would have been reported already, but I can't
find it, so I'm reporting it. AA keys are supposed to be required to be
immutable, but the compiler is not correctly enforcing that. For instance, take
int id = 42;
C c = new C;
cArr[new C] = 42; //should not compile. new C is not immutable.
cArr[c] = 23; //should not compile. c is not immutable.
C value = cArr.keys; //should not compile. keys should be immutable.
int id = 12;
S* s = new S;
sArr[new S] = 7; //should not compile. new S is not immutable.
sArr[s] = 3; //should not compile. s is not immutable.
char str = "g".dup;
strArr[str] = 7; //Correctly fails to compile.
Every single insertion into AA in that could should fail to compile, but only
the char one does. Clearly, dmd is not properly checking for immutability
with objects. It may be that the AA implementation rewrite which is currently
being worked on will need to be completed for this to be properly fixed, but
the longer that it stays like this, the more code that will break once it's
fixed. And it _needs_ to be fixed, because otherwise there are going to be all
kinds of problems with AA keys being changed after they've been used to insert
values into an AA.
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------