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
Child
Expected output:
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.
If the template parameter on `Child` is removed, it returns the correct type.
Comment #1 by andrej.mitrovich — 2014-03-31T05:08:20Z
Seems similar to a bug Vladimir filed recently.
Comment #2 by slavo5150 — 2015-01-25T05:57:05Z
Possibly the same as Issue 13372
Comment #3 by slavo5150 — 2017-08-23T06:04:35Z
A better example:
module test;
import std.stdio;
final abstract class T1
{
final abstract class C(uint value)
{
static uint getValue()
{
return value;
}
}
alias Child = C!2;
}
final abstract class T2
{
final abstract class Child
{
static uint getValue()
{
return 2;
}
}
}
void main()
{
writeln(__traits(parent, T1.Child).stringof); // this should be T1
writeln(__traits(parent, T2.Child).stringof); // this should be, and is, T2
}