Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 29, 2021 It is a bug? | ||||
---|---|---|---|---|
| ||||
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. |
March 29, 2021 Re: It is a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | 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 |
March 30, 2021 Re: It is a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to SealabJaster | 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.
|
March 30, 2021 Re: It is a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to SealabJaster | 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
|
March 30, 2021 Re: It is a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johan Engelen | 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
```
|
Copyright © 1999-2021 by the D Language Foundation