[Issue 12420] [AA] Can't set associative array with array as key value using key type
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Jun 21 01:23:35 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12420
Kenji Hara <k.hara.pg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |INVALID
--- Comment #4 from Kenji Hara <k.hara.pg at gmail.com> ---
(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
--
More information about the Digitalmars-d-bugs
mailing list