Bug 11113 – Strange array initialization result

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-23T21:30:00Z
Last change time
2015-06-09T05:14:44Z
Assigned to
nobody
Creator
daniel350

Comments

Comment #0 by daniel350 — 2013-09-23T21:30:47Z
After adding a constructor to a struct in my code, I noticed my {} initializers were no longer compiling, with a suggestion by the compiler to use ( and ) instead. Understanding this probably means to use the full constructor prototype, not just just replace { with (, I decided to just mass replace the { and ( anyway. The resulting error was actually incredibly strange, and I can't understand the behavior of DMD in this instance, and therefore assume it is a bug. Example: struct Foo { float a, b; } void main() { Foo[] xs = [(0, 1), (2, 3), (4, 5)]; } Result: test.d(6): Error: cannot implicitly convert expression ([1, 3, 5]) of type int[] to Foo[] How/why did it reduce (.., x) to x each time?
Comment #1 by maxim — 2013-09-23T21:45:22Z
Please read struct spec - it tells that adding a struct constructor breaks struct literals. For the question regarding why [(0, 1), (2, 3), (4, 5)] is [1,3,5] please read expression spec page about comma operator. Bugzilla is not a service for asking questions about what you do not understand - please user D.learn instead.
Comment #2 by daniel350 — 2013-09-23T21:51:01Z
Then I guess put this down as just another +1 for DIP19.