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