Bug 11000 – Static field type inference failure

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2013-09-09T16:56:30Z
Last change time
2020-07-04T16:50:58Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
daniel

Comments

Comment #0 by daniel350 — 2013-09-09T16:56:30Z
```struct Foo { int a; this(int a) { this.a = a; } // reason for fail static immutable bar = Foo(1); // fails // static immutable Foo bar = Foo(1); // works } void main() { auto a = Foo.bar; } ``` The code above should compile, instead: `test.d(6): Error: cannot create a struct until its size is determined`. Remove the explicit constructor at line 4, and line 6 compiles. Add the explicit type onto the type declaration (as on line 7), and it will work without removing the explicit constructor.
Comment #1 by andrej.mitrovich — 2013-09-09T18:03:19Z
This looks like a dupe I've seen before. Reduced: ----- struct Foo { this(int) {} static f = Foo(1); } void main() { } -----
Comment #2 by b2.temp — 2020-07-04T16:50:58Z
since 2.068.2 ok