Thread overview
Looking for a workaround
Apr 06, 2022
Guillaume Piolat
Apr 06, 2022
Adam D Ruppe
Apr 06, 2022
Guillaume Piolat
Apr 07, 2022
MoonlightSentinel
Apr 07, 2022
Guillaume Piolat
April 06, 2022

This program fails to build:

import std.traits: getSymbolsByUDA;

struct MyUDA
{
}

class A
{
    @MyUDA int a;
}

class B : A
{
    @MyUDA int b;
}

void main()
{
    alias G = getSymbolsByUDA!(B, MyUDA);
}

Output:

c:\d\ldc2-1.28.0-windows-multilib\bin\..\import\std\traits.d(8933): Error: template
instance `AliasSeq!(b, a)` `AliasSeq!(b, a)` is nested in both `B` and `A`
c:\d\ldc2-1.28.0-windows-multilib\bin\..\import\std\traits.d(8707): Error: template
instance `std.traits.getSymbolsByUDAImpl!(B, MyUDA, "b", "a", "toString", "toHash",
"opCmp", "opEquals", "Monitor", "factory")` error instantiating
main.d(19):        instantiated from here: `getSymbolsByUDA!(B, MyUDA)`
Failed: ["c:\\d\\ldc2-1.28.0-windows-multilib\\bin\\ldmd2.exe", "-v", "-o-", "main.d", "-I."]

Any idea how to workaround that? I really need the same UDA in parent and child class.

April 06, 2022
On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote:
> Any idea how to workaround that?

Works fine if you just use the language instead of the buggy phobos wrappers:

---
    struct MyUDA
    {
    }

    class A
    {
        @MyUDA int a;
    }

    class B : A
    {
        @MyUDA int b;
    }

    void main()
    {
        foreach(memberName; __traits(allMembers, B))
        foreach(attr; __traits(getAttributes, __traits(getMember, B, memberName)))
        static if(is(attr == MyUDA))
                pragma(msg, memberName); // a, b
    }
---

So make a function that does that and applies whatever it is you need to apply and you're in business.

Note that it is `is(typeof(attr) == MyUDA)` if defined `@MyUDA(args)`.
April 06, 2022
On Wednesday, 6 April 2022 at 18:21:11 UTC, Adam D Ruppe wrote:
> On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote:
>> Any idea how to workaround that?
>
> Works fine if you just use the language instead of the buggy phobos wrappers:
>
> ---
>     struct MyUDA
>     {
>     }
>
>     class A
>     {
>         @MyUDA int a;
>     }
>
>     class B : A
>     {
>         @MyUDA int b;
>     }
>
>     void main()
>     {
>         foreach(memberName; __traits(allMembers, B))
>         foreach(attr; __traits(getAttributes, __traits(getMember, B, memberName)))
>         static if(is(attr == MyUDA))
>                 pragma(msg, memberName); // a, b
>     }
> ---
>
> So make a function that does that and applies whatever it is you need to apply and you're in business.
>
> Note that it is `is(typeof(attr) == MyUDA)` if defined `@MyUDA(args)`.

Thanks, it will also create less templates.
April 07, 2022

On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote:

>

Any idea how to workaround that? I really need the same UDA in parent and child class.

Use a frontend >= dmd 2.099, it works according to run.dlang.io.

April 07, 2022
On Thursday, 7 April 2022 at 12:56:05 UTC, MoonlightSentinel wrote:
> On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote:
>> Any idea how to workaround that? I really need the same UDA in parent and child class.
>
> Use a frontend >= dmd 2.099, it works according to run.dlang.io.

Good to know, thanks.