https://issues.dlang.org/show_bug.cgi?id=12420
Kenji Hara <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #4 from Kenji Hara <[email protected]> --- (In reply to Denis Shelomovskij from comment #3) > Looks like you misunderstood me. The word `immutable` shouldn't be here, > it's just an incorrect error message. Currently we have no rules disallowing > non-`immutable` associative array keys. I filed Issue 12491 for this. > > This issue will be auto-fixed if Issue 2954 will be fixed by applying a > correct check to ensure key expression can be implicitly converted to AA key > type in case of setting AA value. In D, AA requires immutability for the key. In evidence all AA key types are implicitly qualified with const. int[char[]] aa; pragma(msg, typeof(aa)); // Prints: int[const(char)[]] Honesty, key type should be qualified with immutable. Currently int[const(char[])] can accept char[] key when storing value in the AA, but it's a known issue. Anyway in D AA types cannot have mutable key. Therefore this issue should be marked as invalid.(In reply to Denis Shelomovskij from comment #0) > This code should compile: > --- > void main() > { > int[char[]] aa; > aa[new char[1]] = 5; // line 4 > } > --- > main.d(4): Error: associative arrays can only be assigned values with > immutable keys, not char[] > --- > > Also the error message is wrong. The compiler expects an array of > not-mutable elements (yes, `cast(const)` will work). This incorrect compiler > hack [1] was introduced trying to fix Issue 2954 (see Comment 8 of that > issue). I propose to remove the hack. > > And yes, it's a regression from 2010. ) > > > [1] http://www.dsource.org/projects/dmd/changeset/749 --
