www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - It is a bug?

reply Jack Applegame <japplegame gmail.com> writes:
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
parent reply SealabJaster <sealabjaster gmail.com> writes:
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
next sibling parent Jack Applegame <japplegame gmail.com> writes:
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:
 ...
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
Thanks.
Mar 29
prev sibling parent reply Johan Engelen <j j.nl> writes:
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:
 ...
This is due to implicit nesting: https://dlang.org/spec/template.html#implicit-nesting
But the symbol `Foo.t` isn't local, so then implicit nesting shouldn't happen? thanks, Johan
Mar 30
parent SealabJaster <sealabjaster gmail.com> writes:
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