Bug 13209 – Refused union initialization

Status
RESOLVED
Resolution
INVALID
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-07-27T06:26:00Z
Last change time
2014-07-27T21:02:38Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-07-27T06:26:14Z
This used to work in dmd 2.065: struct Foo { union { immutable static struct { double x, y; } immutable double[2] v; } Foo bar() { return Foo(y, x); } } void main() {} dmd 2.066beta4 gives: test.d(7,19): Error: more initializers than fields (1) of Foo
Comment #1 by k.hara.pg — 2014-07-27T13:52:19Z
Introduced in: https://github.com/D-Programming-Language/dmd/pull/3400 However I think this is not a regression, because > struct Foo { > union { > immutable static struct { double x, y; } This line is an anonymous struct declaration with 'static' attribute, so x and y should become immutable static field. Therefore > immutable double[2] v; > } > Foo bar() { > return Foo(y, x); > } > } > void main() {} > > > dmd 2.066beta4 gives: > > test.d(7,19): Error: more initializers than fields (1) of Foo In git head, Foo.x and Foo.y are correctly analyzed as static fields, and Foo has only one instance field v.
Comment #2 by public — 2014-07-27T21:02:38Z
> This line is an anonymous struct declaration with 'static' attribute, so x and y should become immutable static field. Is this documented anywhere? Can't see it at http://dlang.org/struct.html and this is different from named struct behavior.