[Issue 18611] New: struct initializer works for dynamic arrays but not associative arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 14 17:00:43 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18611

          Issue ID: 18611
           Summary: struct initializer works for dynamic arrays but not
                    associative arrays
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: andre at s-e-a-p.de

Although the coding in the dmd looks almost identical for dynamic arrays and
associative arrays, following example works only for dynamic arrays.

https://github.com/dlang/dmd/blob/master/src/dmd/initsem.d#L634

struct Bar
{
    string s;
}

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

void main()
{
    Foo foo = {
        arr: [{s: "123"}],
        asso: ["0": {s: "123"}] // not an associative array initializer
    };
}

Although there is an DIP, this might be more a bug fix, as it works well for
dynamic arrays. Providing the same support for associative arrays seems natural

--


More information about the Digitalmars-d-bugs mailing list