Summary: AAs change key type
           Product: D
           Version: unspecified
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime

--- Comment #0 from 2010-06-06 04:54:52 PDT ---
With DMD v2.046 this program prints  const(char)[]  instead of  char[] 

import std.stdio: writeln;
void main() {
    int[char[]] data = [cast(char[])"foo" : 1];
    foreach (key, val; data)

Modifying AA keys after they are inserted in the AA is indeed bad because their
hash value and position inside the AA doesn't get recomputed.

But the current design/behaviour is surprising and bad, because I have asked
for a key type and the runtime/compiler gives me a different key type (forcing
me to use casts). There are two possible behaviours that I see acceptable here:

1) to disallow AAs with mutable keys, their literals and definition too (as
Python does), so in this case this variable definition becomes a compile-time
int[int[]] data;
2) or to allow mutable keys (and hope the programmer will not mutate them) (as
I think D1 does), and keep their type unchanged (mutable).

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

Reply via email to