Bug 20905 – Type definition inside a static if results in an undefined identifier

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-06-07T18:01:11Z
Last change time
2024-12-13T19:09:06Z
Assigned to
No Owner
Creator
KytoDragon
See also
https://issues.dlang.org/show_bug.cgi?id=21171, https://issues.dlang.org/show_bug.cgi?id=17883, https://issues.dlang.org/show_bug.cgi?id=16666
Moved to GitHub: dmd#19717 →

Comments

Comment #0 by kytodragon — 2020-06-07T18:01:11Z
This code: struct Bar { Foo foo; } static if (true) { alias my_type = ushort; } struct Foo { my_type index; } results in this error: test.d(11): Error: undefined identifier `my_type` Removing Bar or moving Bar after the static if fixes it. This also happens, if Bar is defined in another file and imported into the one with the static if. Reproduced on Windows x64 with DMD 2.092.0 and LDC 1.21.0.
Comment #1 by kytodragon — 2020-06-14T13:14:52Z
I changed the importance to major since if you import the file that contains the static if this can't even be fixed by reordering symbols/imports.
Comment #2 by kytodragon — 2020-10-03T09:55:19Z
It turns out you don't even need an alias for it to fail: struct Bar { Foo foo; } static if (true) { struct my_type { int a; } } struct Foo { my_type index; } test.d(12): Error: undefined identifier `my_type`
Comment #3 by dlang — 2020-11-08T19:39:01Z
It seems that this depends on the definition order. A reduced example: ``` struct Foo { my_type index; } static if(true) { alias my_type = int; } ``` Error: undefined identifier my_type This example works: ``` static if(true) { alias my_type = int; } struct Foo { my_type index; } ```
Comment #4 by robert.schadek — 2024-12-13T19:09:06Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19717 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB