__traits(parent) bug?
Paul Backus
snarwin at gmail.com
Sat Oct 24 15:45:03 UTC 2020
On Friday, 23 October 2020 at 14:12:59 UTC, Jack Applegame wrote:
>> struct Foo {
>> struct Bar(T) {
>> T x;
>> }
>> }
>
> I expect the value of `__traits(parent, Foo.Bar!int)` is `Foo`,
> but it is `Foo.Bar!int`.
>
> Yes, it looks like the type is the parent of itself. :-)
>
> I know that `Foo.Bar!int` is internally `Foo.Bar!int.Bar`, but
> I believe this behavior of `__traits(parent)` is wrong.
>
> Also consider, please, another question -
> https://forum.dlang.org/thread/oyysbwgkycbmwuoifkky@forum.dlang.org
IMO the real issue here is that, even if you apply
__traits(parent) multiple times, the compiler will never give you
`Foo`, because it re-evaluates the result of each
__traits(parent) expression from `Foo.Bar!int` (the template) to
`Foo.Bar!int.Bar` (the eponymous member).
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.
More information about the Digitalmars-d
mailing list