digitalmars.D - __traits(parent) bug?
- Jack Applegame (7/12) Oct 23 2020 I expect the value of `__traits(parent, Foo.Bar!int)` is `Foo`,
- Paul Backus (9/21) Oct 24 2020 IMO the real issue here is that, even if you apply
- Stefan Koch (4/8) Oct 24 2020 The rewrite to get the eponymous member is applied to the parent
- Paul Backus (13/25) Oct 24 2020 This paragraph refers specifically to "a template instantiation",
- Imperatorn (2/11) Oct 25 2020 Where is this behavior documented?
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
Oct 23 2020
On Friday, 23 October 2020 at 14:12:59 UTC, Jack Applegame wrote: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.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
Oct 24 2020
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.
Oct 24 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:Here's how the language spec defines the rewrite rule: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.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 instantiationThis 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
Oct 24 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:Where is this behavior documented?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.
Oct 25 2020