www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Bug? Can't init an AA of different-length strings

reply "Nick Sabalausky" <a a.a> writes:
I'd put this into Bugzilla, but I wanted to check first if there was 
something I was misunderstanding:

void main()
{
    // Ok
    char[][] strsA = ["333", "22", "4444"];

    // Ok
    char[][char] strsB = ['3':"333", '2':"222", '4':"444"];

    // Ok
    char[][char] strsC;
    strsC['3'] = "333";
    strsC['2'] = "22";
    strsC['4'] = "4444";

    // Error: cannot implicitly convert expression ("22") of type char[2u] 
to char[3u]
    // Error: cannot implicitly convert expression ("4444") of type char[4u] 
to char[3u]
    char[][char] strsD = ['3':"333", '2':"22",  '4':"4444"];
}

On that last one, strsD, the compiler seems to interpret it as 
"char[lengthOfFirstStringLiteral][char]", in this case, "char[3][char]", 
instead of using char[][char]. Is this really supposed to be happening, or 
is it a bug? 
Oct 04 2008
parent bearophile <bearophileHUGS lycos.com> writes:
It's one of the many "bugs" present in the literals. I have listed 5-8 bugs of
different kinds like this.

The type is taken from the first item, so after the first string you can put a
.dup or [].

Bye,
bearophile
Oct 04 2008