Initialization of the Associative arrays

Moritz Warning moritzwarning at web.de
Mon Jul 14 09:24:20 PDT 2008


On Mon, 14 Jul 2008 10:07:15 -0400, baleog wrote:

> Hello,
> 
> Is it a bug that i can't do like this: int[string] x = ["11":11, "1":1];
> Error: cannot implicitly convert expression ("1") of type
> invariant(char[1u]) to invariant(char[2u])
> 
> dmd-2.0.16
> 
> Thanks

DMD deduce the type of the literal from it's first element.
int[string] x = [cast(char[]) "11":11, "1":1];
would work. "11"[] is a shortcut.

Imho, the left side type declaration should be honored by the compiler
by adding a cast to the first literal element after initial parsing.


More information about the Digitalmars-d-learn mailing list