__traits(parent) bug?

Paul Backus snarwin at gmail.com
Sat Oct 24 19:53:25 UTC 2020


  On Saturday, 24 October 2020 at 17:46:55 UTC, Stefan Koch wrote:
> On Saturday, 24 October 2020 at 15:45:03 UTC, Paul Backus wrote:
>
>>
>> I'm not sure that this can really be called a bug, per se--the 
>> language spec is vague enough to allow either 
>> interpretation--but I'd be very surprised if this behavior was 
>> intentional.
>
> The rewrite to get the eponymous member is applied to the 
> parent :)
> Not intentional but a consequence of the rewrite rule.

Here's how the language spec defines the rewrite rule:

> If a template contains members whose name is the same as the 
> template identifier then these members are assumed to be 
> referred to in a template instantiation

This paragraph refers specifically to "a template instantiation", 
which is defined on the same page as either an explicit 
instantiation of the form `Template!Args` [1], or an implicit 
instantiation of a function template [2]. A __traits expression 
is neither of these.

So, it's a consequence of the way the rewrite rule is currently 
implemented, but the spec would also permit an implementation 
that worked differently.

[1] 
https://dlang.org/spec/template.html#explicit_tmp_instantiation
[2] https://dlang.org/spec/template.html#function-templates


More information about the Digitalmars-d mailing list