Andrej Mitrovic <> changed:

           What    |Removed                     |Added
                 CC|                            |

--- Comment #1 from Andrej Mitrovic <> 2010-08-29 
21:07:55 PDT ---
As of 2.048, and according to my tests, DMD forces AA's to have a const type as
the key type. For example:

import std.stdio: writeln;
void main() 
    int[int[]] data;

Prints: int[const(int)[]]

And your AA literal key type gets converted to a const type as well:

import std.stdio: writeln;
void main() 
    writeln(typeid([cast(char[])"foo" : 1]));

Prints: int[const(char)[]]

What happens here (if my interpretation is right), is that foo is first an
array of immutable chars, it's casted to a mutable array of chars, and then DMD
sees it is a key of an AA literal so it converts it to an array of const chars.

So DMD is most probably doing this:

On the left of assignment:
int[char[]] data 
-> int[const(char)[]] data

On the right of assignment:
[cast(char[])const(char)[] : int] 
-> int[cast(char[])const(char)[]] 
-> int[char[]]
-> int[const(char)[]]

And the whole thing becomes:

int[const(char)[]] data = int[const(char)[]]

So if I got that right then DMD automatically changes the key type of an AA to
be const, regardless of any casts. Having to change int[] to const(int)[]
directly in the code would probably make the AA's harder to read, so maybe
that's a good thing.

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

Reply via email to