digitalmars.D - It is a bug?
- Jack Applegame (3/26) Mar 29 2021 Looks weird.
- SealabJaster (8/9) Mar 29 2021 This is due to implicit nesting:
- Jack Applegame (2/11) Mar 29 2021 Thanks.
- Johan Engelen (5/9) Mar 30 2021 But the symbol `Foo.t` isn't local, so then implicit nesting
- SealabJaster (23/24) Mar 30 2021 Unfortunately not, it seems to happen when passing an alias
This code doesn't compile:import std.stdio; struct Foo { (123) int t; } void printUDA(alias bar)() { writeln(__traits(getAttributes, bar)); } void main() { printUDA!(Foo.t); // Error: need this for printUDA of type safe void() }but I found a funny workaround:import std.stdio; struct Foo { (123) int t; } static void printUDA(alias bar)() { // <------- add static writeln(__traits(getAttributes, bar)); } void main() { printUDA!(Foo.t); }Looks weird.
Mar 29 2021
On Monday, 29 March 2021 at 17:57:53 UTC, Jack Applegame wrote:...This is due to implicit nesting: https://dlang.org/spec/template.html#implicit-nesting I've been bitten by this a lot. Honestly it's a bit broken IMO, because it allows for issues such as 21496, which is honestly a bit embarrassing: https://issues.dlang.org/show_bug.cgi?id=21496 Also I think it's the cause of issue 21377: https://issues.dlang.org/show_bug.cgi?id=21377
Mar 29 2021
On Monday, 29 March 2021 at 19:27:18 UTC, SealabJaster wrote:On Monday, 29 March 2021 at 17:57:53 UTC, Jack Applegame wrote:Thanks....This is due to implicit nesting: https://dlang.org/spec/template.html#implicit-nesting I've been bitten by this a lot. Honestly it's a bit broken IMO, because it allows for issues such as 21496, which is honestly a bit embarrassing: https://issues.dlang.org/show_bug.cgi?id=21496 Also I think it's the cause of issue 21377: https://issues.dlang.org/show_bug.cgi?id=21377
Mar 29 2021
On Monday, 29 March 2021 at 19:27:18 UTC, SealabJaster wrote:On Monday, 29 March 2021 at 17:57:53 UTC, Jack Applegame wrote:But the symbol `Foo.t` isn't local, so then implicit nesting shouldn't happen? thanks, Johan...This is due to implicit nesting: https://dlang.org/spec/template.html#implicit-nesting
Mar 30 2021
On Tuesday, 30 March 2021 at 11:17:55 UTC, Johan Engelen wrote:...Unfortunately not, it seems to happen when passing an alias directly to any nested symbol. e.g. ``` struct MyStruct { int a; } void f(alias a)() { pragma(msg, __FUNCTION__); } alias fi = f!(MyStruct.a); ``` Prints `onlineapp.MyStruct.f!(a).f` where you can clearly see that `f!(a)` is nested into `MyStruct`. This also creates certain limitations such as: ``` struct A { int a; } struct B { int b; } void f(alias a, alias b)(){} alias fi = f!(A.a, B.b); // onlineapp.d(4): Error: template instance f!(a, b) f!(a, b) is nested in both A and B ```
Mar 30 2021