digitalmars.D - Potential bug in __traits(parent).
Consider the following code: /*********** mmio.d ************/ module mmio; mixin template HasValue(uint value) { static uint getValue() { return value; } } mixin template Parent() { final abstract class Child(uint value) { mixin HasValue!(value); } } /*********** test.d ************/ module test; import mmio; mixin Parent; alias Two = Child!(2); /*********** main.d ************/ import std.stdio; import test; void main() { writeln(__traits(parent, test.Two).stringof); writeln(__traits(parent, __traits(parent, test.Two)).stringof); readln(); } DMD 2.065 Output: Child!(2) Child!(2) GDC 4.8.2 20130725 Output: Child Child LDC 0.12.1 Output: Child Chlld All of these seem wrong to me. What I expect for output is: module test {the second `writeln` shouldn't compile since `test` has no parent} A couple of observations: 1. `Child` is not the parent of `test.Two`, `test` is the parent of `test.Two`. 2. If you believe `__traits(parent, test.Two)` is `Child`, `Child` should not be its own parent. Incidentally, if I remove the template parameter on `Child`, I get the results I expect. Could someone please confirm if this is a bug or not? Thanks for the help, Mike
Mar 28 2014
On Saturday, 29 March 2014 at 03:00:30 UTC, Mike wrote:Consider the following code: /*********** mmio.d ************/ module mmio; mixin template HasValue(uint value) { static uint getValue() { return value; } } mixin template Parent() { final abstract class Child(uint value) { mixin HasValue!(value); } } /*********** test.d ************/ module test; import mmio; mixin Parent; alias Two = Child!(2); /*********** main.d ************/ import std.stdio; import test; void main() { writeln(__traits(parent, test.Two).stringof); writeln(__traits(parent, __traits(parent, test.Two)).stringof); readln(); } DMD 2.065 Output: Child!(2) Child!(2) GDC 4.8.2 20130725 Output: Child Child LDC 0.12.1 Output: Child Chlld All of these seem wrong to me. What I expect for output is: module test {the second `writeln` shouldn't compile since `test` has no parent} A couple of observations: 1. `Child` is not the parent of `test.Two`, `test` is the parent of `test.Two`. 2. If you believe `__traits(parent, test.Two)` is `Child`, `Child` should not be its own parent. Incidentally, if I remove the template parameter on `Child`, I get the results I expect. Could someone please confirm if this is a bug or not? Thanks for the help, Mikehttps://d.puremagic.com/issues/show_bug.cgi?id=12496
Mar 30 2014