Bug 9181 – Forward reference error in struct static fields

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-18T18:36:00Z
Last change time
2024-12-13T18:03:28Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
bearophile_hugs
Blocks
340
Moved to GitHub: dmd#18507 →

Comments

Comment #0 by bearophile_hugs — 2012-12-18T18:36:00Z
This program compiles with no errors: struct Foo { static immutable F = Foo(); static immutable Foo[] foos1 = [F]; } void main() {} If I remove the type of foos1 it doesn't compile: struct Foo { static immutable F = Foo(); static immutable foos1 = [F]; } void main() {} DMD 2.061alpha gives: test.d(3): Error: forward reference of variable F
Comment #1 by b2.temp — 2019-04-04T10:34:33Z
Funnily this alternative, which still needs inference for the array, works --- struct Foo { static immutable foos1 = [F]; static immutable F = Foo(); } --- Because type semantic of `F` is launched when doing the one of `foo1`, hence `F` is not already "inuse".
Comment #2 by robert.schadek — 2024-12-13T18:03:28Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18507 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB