www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - getOverloads __traits does not seem to include instances of the

reply user1234 <user1234 12.de> writes:
I find this a bit odd

```d
enum IncludeTemplate = true;

///

void v0(T)(T t){}
void v0(){}
void v0(int){}

static assert(__traits(getOverloads, mixin(__MODULE__), "v0", 
IncludeTemplate).length == 3);

///

void v1(T)(T t){}
void v1(){}
alias v1_OfInt = v1!int;

static assert(__traits(getOverloads, mixin(__MODULE__), "v1", 
IncludeTemplate).length == 3); // fails
```

The problem is that you cannot add a member using an alias with 
the same name

```d
void v2(T)(T t){}
void v2(){}
alias v2 = v2!int;

static assert(__traits(getOverloads, mixin(__MODULE__), "v2", 
IncludeTemplate).length == 3);
```

 Error: template instance `v2!int` `v2!int` forward references 
 template declaration `v2(T)(T t)`
I see a problem here, what do you think ?
Mar 02
parent reply monkyyy <crazymonkyyy gmail.com> writes:
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 ``` ```d void v1(T)(){}; alias v1()= typeof(&v1!int);//valid unittest{ v1!() foo; v1!(int); } ``` alias's without () are not real `names` and in practice my best guess of their operation is they append what they see to an overload set. https://crazymonkyyy.github.io/blackmagic-in-d/overloadset1.html whatever your trying to do, take care to make your overload sets aliases be lazy templates and they should behave better
Mar 02
parent reply user1234 <user1234 12.de> writes:
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.
Mar 02
parent reply monkyyy <crazymonkyyy gmail.com> writes:
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
Mar 02
parent reply user1234 <user1234 12.de> writes:
On Monday, 2 March 2026 at 12:13:15 UTC, monkyyy wrote:
 ```d
 import std;
 ```
mmh. why ?
Mar 02
parent user1234 <user1234 12.de> writes:
On Monday, 2 March 2026 at 12:24:00 UTC, user1234 wrote:
 On Monday, 2 March 2026 at 12:13:15 UTC, monkyyy wrote:
 ```d
 import std;
 ```
mmh. why ?
I mean pragma(msg) is able enough
Mar 02