digitalmars.D.learn - alias and __VERSION__ condition doesn't play well
- frame (30/30) Jan 17 2022 At the very top of my module I have this declaration:
- vit (9/39) Jan 17 2022 static ifs and mixins need semantic analysis to expand, but when
- Paul Backus (2/16) Jan 18 2022 Works for me: https://run.dlang.io/is/XZlvQ8
- vit (3/21) Jan 18 2022 It works until you have cyclic dependencies:
- Steven Schveighoffer (5/29) Jan 18 2022 Has nothing to do with `__VERSION__`:
- vit (19/49) Jan 18 2022 In dmd is order of module compilation different.
At the very top of my module I have this declaration: ```d static if (__VERSION__ >= 2098) { alias Foo = TypeA; } else { alias Foo = TypeB; } ``` No problem inside the module itself but this doesn't work when imported from another module: Error: undefined identifier `Foo` While this workaround works: ```d template getAlias() { static if (__VERSION__ >= 2098) { alias getAlias = TypeA; } else { alias getAlias = TypeB; } } alias Foo = getAlias!(); ``` Is there a reason for that?
Jan 17 2022
On Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote:At the very top of my module I have this declaration: ```d static if (__VERSION__ >= 2098) { alias Foo = TypeA; } else { alias Foo = TypeB; } ``` No problem inside the module itself but this doesn't work when imported from another module: Error: undefined identifier `Foo` While this workaround works: ```d template getAlias() { static if (__VERSION__ >= 2098) { alias getAlias = TypeA; } else { alias getAlias = TypeB; } } alias Foo = getAlias!(); ``` Is there a reason for that?static ifs and mixins need semantic analysis to expand, but when you import module, the semantic analysis doesn't run yet (depends on order). Beter workaround is: ```d import std.traits : Select; alias Foo = Select!(__VERSION__ >= 2098, TypeA, TypeB); ```
Jan 17 2022
On Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote:At the very top of my module I have this declaration: ```d static if (__VERSION__ >= 2098) { alias Foo = TypeA; } else { alias Foo = TypeB; } ``` No problem inside the module itself but this doesn't work when imported from another module: Error: undefined identifier `Foo`Works for me: https://run.dlang.io/is/XZlvQ8
Jan 18 2022
On Tuesday, 18 January 2022 at 12:05:38 UTC, Paul Backus wrote:On Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote:It works until you have cyclic dependencies: https://run.dlang.io/is/wDDcK5At the very top of my module I have this declaration: ```d static if (__VERSION__ >= 2098) { alias Foo = TypeA; } else { alias Foo = TypeB; } ``` No problem inside the module itself but this doesn't work when imported from another module: Error: undefined identifier `Foo`Works for me: https://run.dlang.io/is/XZlvQ8
Jan 18 2022
On 1/18/22 7:19 AM, vit wrote:On Tuesday, 18 January 2022 at 12:05:38 UTC, Paul Backus wrote:Has nothing to do with `__VERSION__`: https://run.dlang.io/is/pa8lDy That does seem like a bug. And it's LDC specific, dmd seems to work fine. -SteveOn Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote:It works until you have cyclic dependencies: https://run.dlang.io/is/wDDcK5At the very top of my module I have this declaration: ```d static if (__VERSION__ >= 2098) { alias Foo = TypeA; } else { alias Foo = TypeB; } ``` No problem inside the module itself but this doesn't work when imported from another module: Error: undefined identifier `Foo`Works for me: https://run.dlang.io/is/XZlvQ8
Jan 18 2022
On Wednesday, 19 January 2022 at 04:15:54 UTC, Steven Schveighoffer wrote:On 1/18/22 7:19 AM, vit wrote:In dmd is order of module compilation different. Same problem: https://run.dlang.io/is/NkySAw This is not only problem with imports: ```d class Foo{ Bar.B b; static if(true) alias F = int; } class Bar{ Foo.F f; //Error: no property `F` for type `onlineapp.Foo` static if(true) alias B = int; } void main(){} ```On Tuesday, 18 January 2022 at 12:05:38 UTC, Paul Backus wrote:Has nothing to do with `__VERSION__`: https://run.dlang.io/is/pa8lDy That does seem like a bug. And it's LDC specific, dmd seems to work fine. -SteveOn Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote:It works until you have cyclic dependencies: https://run.dlang.io/is/wDDcK5At the very top of my module I have this declaration: ```d static if (__VERSION__ >= 2098) { alias Foo = TypeA; } else { alias Foo = TypeB; } ``` No problem inside the module itself but this doesn't work when imported from another module: Error: undefined identifier `Foo`Works for me: https://run.dlang.io/is/XZlvQ8
Jan 18 2022