getOverloads __traits does not seem to include instances of the generic members
monkyyy
crazymonkyyy at gmail.com
Mon Mar 2 12:13:15 UTC 2026
On Monday, 2 March 2026 at 11:48:09 UTC, user1234 wrote:
> On Monday, 2 March 2026 at 11:23:25 UTC, monkyyy wrote:
>> On Monday, 2 March 2026 at 10:53:30 UTC, user1234 wrote:
>>>
>>> ```d
>>> void v2(T)(T t){}
>>> void v2(){}
>>> alias v2 = v2!int;
>>>
>>>> Error: template instance `v2!int` `v2!int` forward
>>>> references template declaration `v2(T)(T t)`
>>
>> I think thats the wrong error message but Im not convinced its
>> wrong to give an error
>>
>> ```d
>> void v1(T)();
>> alias v1= bool;//error
>> ```
>
> For this case the compiler can check whether that's for a
> function... oh crap we also have eponymous templates...
>
> Really the problem is that we cannot grow the set, while the v0
> and v1 sets are equivalent. Or maybe in the compiler internals,
> the set is well updated, problem is that then when you iterate,
> the count is wrong...
>
> An example more closed to a real use-case:
>
> ```d
> void v3(T)(T t){}
> void v3(){}
>
> enum IncludeTemplate = true;
> static if (__traits(compiles, mixin("v3(0)"))) // should add an
> instance to the set
> {
> pragma(msg, "yeah were are in the branch...");
> static assert (__traits(getOverloads, mixin(__MODULE__),
> "v3", IncludeTemplate).length == 3);
> }
> ```
>
> According to me the test on the mixin should have for effect to
> update the overload set.
Overload sets are headers not initializations and the trait is
basicly useless
```d
import std;
static struct S{
static void v4(T)(){}
}
unittest{
S.v4!int;
S.v4!bool;
S.v4!float;
__traits(getOverloads,S,"v4").stringof.writeln;//guess what
this prints
}
```
The compiles mixin *shouldnt* have an effect(it would tho) it in
theory suppose to unwind its effects
More information about the Digitalmars-d
mailing list