Why does struct initializer works for arrays but not for associative arrays?

Andre Pany andre at s-e-a-p.de
Wed Mar 14 13:36:51 UTC 2018


Hi,

I do not understand why struct initializer works for arrays but 
not for
associative arrays:

struct Bar
{
     string s;
}

struct Foo
{
     Bar[string] asso;
     Bar[] arr;
}

void main()
{
     Foo foo = {
         arr: [{s: "123"}],
         asso: ["0": {s: "123"}] // does not work
     };
}

The coding for both types of arrays looks very similiar:
https://github.com/dlang/dmd/blob/9ed779a7d68d2ac489338cc4758c10d0cb169b39/src/dmd/initsem.d#L634

I cannot spot the difference.

Kind regards
André


More information about the Digitalmars-d-learn mailing list