Bug 14977 – Struct initializer doesn't work inside AA initializer

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-29T12:56:00Z
Last change time
2015-09-01T12:46:45Z
Assigned to
nobody
Creator
japplegame

Comments

Comment #0 by japplegame — 2015-08-29T12:56:29Z
struct Foo { int a; } void main() { // compiles Foo[] arr = [ {a: 1}, {a: 2} ]; // compiles Foo[int] aa1 = [ 1: Foo(), 2: Foo() ]; // Error: not an associative array initializer Foo[int] aa2 = [ 1: {a: 1}, 2: {a: 2} ]; }
Comment #1 by dlang-bugzilla — 2015-09-01T11:57:51Z
I'm surprised you can use struct initializers in an array, I thought you could only use them to immediately initialize a single variable. I think this is an enhancement request, not a bug, unless the language spec says this should work.
Comment #2 by k.hara.pg — 2015-09-01T12:44:37Z
(In reply to Vladimir Panteleev from comment #1) > I'm surprised you can use struct initializers in an array The struct initializers are used inside "array initializers*. There's no syntactic problem, and should it work. *** This issue has been marked as a duplicate of issue 6469 ***
Comment #3 by dlang-bugzilla — 2015-09-01T12:46:45Z
(In reply to Kenji Hara from comment #2) > The struct initializers are used inside "array initializers*. There's no > syntactic problem, and should it work. Makes sense, thanks.