D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 18611 - struct initializer works for dynamic arrays but not associative arrays
Summary: struct initializer works for dynamic arrays but not associative arrays
Status: RESOLVED DUPLICATE of issue 9443
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-14 17:00 UTC by Andre
Modified: 2023-01-31 11:10 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andre 2018-03-14 17:00:43 UTC
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
Comment 1 RazvanN 2023-01-31 11:10:54 UTC

*** This issue has been marked as a duplicate of issue 9443 ***