getSymbolsByUDA in constructor/member functions

frame frame86 at live.com
Thu Jun 16 13:27:25 UTC 2022


On Thursday, 16 June 2022 at 09:29:36 UTC, Arafel wrote:

> Classes can have static members just as structs, so I don't 
> think you always need an instance for a class either.

Well, ok.

> So if you call `getMember` from a member function, it adds the 
> hidden `this` reference, and this has subtle consequences later 
> on, even if `this.C` is practically just an alias for `C`.
>
> I still think this is a bug in `getMember`, although perhaps 
> not as obvious as I first thought.

Maybe you are right. I also don't see why the `this` reference 
should be there in the static call.

But it looks like a compiler bug since the output of 
`getSymbolsByUDA` is just an alias sequence and nothing should 
happen before consuming it?

This works fine too:

```d
class C
{
     @E int a;

     void foo()
     {
         alias seq = getSymbolsByUDA!(C, E);
         static foreach (i; 0 .. seq.length)
         {
             pragma(msg, hasUDA!(seq[i], E));
         }
     }
}
```


More information about the Digitalmars-d-learn mailing list