Bug 18611 – struct initializer works for dynamic arrays but not associative arrays
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-14T17:00:43Z
Last change time
2023-01-31T11:10:54Z
Assigned to
No Owner
Creator
Andre
Comments
Comment #0 by andre — 2018-03-14T17:00:43Z
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 by razvan.nitu1305 — 2023-01-31T11:10:54Z
*** This issue has been marked as a duplicate of issue 9443 ***