Thread overview
__traits(parent) borken on templates
Dec 12, 2017
Shachar Shemesh
Dec 12, 2017
Stefan Koch
Dec 12, 2017
Shachar Shemesh
December 12, 2017
module foo;

import std.traits;

void bar(T)() {
}

pragma(msg, "id:          ", fullyQualifiedName!(bar));
pragma(msg, "parent:      ", fullyQualifiedName!(__traits(parent, bar)));

pragma(msg, "id:          ", fullyQualifiedName!(bar!int));
pragma(msg, "parent:      ", fullyQualifiedName!(__traits(parent, bar!int)));
pragma(msg, "grandparent: ", fullyQualifiedName!(__traits(parent, __traits(parent, bar!int))));


Compile, and the result is:
id:          foo.bar
parent:      foo
id:          foo.bar!(int)
parent:      foo.bar!(int)
grandparent: foo.bar!(int)

Once the object you have is an inside template, you cannot get its parent. I suspect the reason is that bar is actually defined as:

template bar(T) {
  void bar() {
  }
}

So asking for the function's parent supposedly returns the template. This doesn't live up to scrutiny, though, because the template's parent is the module, but asking for the parent of the parent still returns the function.
December 12, 2017
On Tuesday, 12 December 2017 at 14:49:04 UTC, Shachar Shemesh wrote:
> module foo;
>
> import std.traits;
>
> [...]

A template is not a symbol as is.
And eponymous templates alias them-selfs to the symbol they define on instancing
December 12, 2017
On 12/12/17 17:20, Stefan Koch wrote:
> On Tuesday, 12 December 2017 at 14:49:04 UTC, Shachar Shemesh wrote:
>> module foo;
>>
>> import std.traits;
>>
>> [...]
> 
> A template is not a symbol as is.
> And eponymous templates alias them-selfs to the symbol they define on instancing

And yet, "bar", which is a template, works, but "bar!int", which is an identifier, doesn't.

Shachar