getSymbolByUDA and inheritance

Arafel er.krali at gmail.com
Thu Apr 19 15:32:58 UTC 2018


Hi,

getSymbolsByUDA doesn't work when inheritance is involved [1]:

```
import std.traits;

void main()
{
     pragma(msg, getSymbolsByUDA!(A,S).length);
     pragma(msg, getSymbolsByUDA!(B,S).length);
}

class A {
     @S("A") int a;
}

class B : A {
     @S("B") int b;
}

struct S {
     string name;
}
```

The error message seems a bit weird, and after some tinkering, I've been 
able to reproduce it when creating an AliasSeq with members of both the 
parent and the child class [2]:

```
import std.meta;

void main()
{
	pragma(msg, AliasSeq!(__traits(getMember, B, "a"), __traits(getMember, 
B, "b")));
}

class A {
     int a;
}

class B : A {
     int b;
}
```

It seems that using __traits(getMember,...) is introducing some kind of 
hidden context to the actual class that defines the member... It looks 
like a bug to me, but there might be a reason to do it this way.

Still, whatever the reason, it definitely breaks getSymbolsByUDA when 
inheritance is involved. According to the documentation [3] only nested 
members are excluded (and in any they are just excluded, but still 
compile), so is this a bug?

[1]: https://run.dlang.io/is/502CUB
[2]: https://run.dlang.io/is/9wOIsa
[3]: https://dlang.org/library/std/traits/get_symbols_byuda.html


More information about the Digitalmars-d-learn mailing list