Summary: dmd accepts mutable AA key types for objects
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD

--- Comment #0 from Jonathan M Davis <> 2012-09-17 13:29:18 
PDT ---
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
this code:

void main()
    class C
        int id = 42;

    C c = new C;
    int[C] cArr;

    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[0]; //should not compile. keys[0] should be immutable.;

    struct S
        int id = 12;

    S* s = new S;
    int[S*] sArr;

    sArr[new S] = 7; //should not compile. new S is not immutable.
    sArr[s] = 3; //should not compile. s is not immutable.

    int[char[]] strArr;
    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:
------- You are receiving this mail because: -------

Reply via email to