Wrong lowering for a[b][c]++

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Mar 22 22:11:05 PDT 2012


On 3/23/12, H. S. Teoh <hsteoh at quickfur.ath.cx> wrote:
> I'm guessing the compiler thinks the literal is an array literal, or
> maybe something went awry with the internal AA hacks that it currently
> has.

struct Foo
{
    string[int] aa;
    alias aa this;
}

void main()
{
    Foo x = [1 : "4"];
}

test.d(22): Error: cannot use array to initialize Foo

Borken to the bone. I don't know whether there's a bug report open on this.

Btw, want to see a magic trick? Put this into your hash:

this(AA)(AA aa)
    if (std.traits.isAssociativeArray!AA
        && is(KeyType!AA == keytype)
        && is(ValueType!AA == valuetype))
{
    foreach (key, val; aa)
        this[key] = val;
}

And theeeen..... *drumroll*:

AA!(string,int) bb = cast()["abc":123];

badoom-tshhh. LOL!


More information about the Digitalmars-d mailing list