[Issue 12496] New: __traits(parent, x) returns incorrect type

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 30 22:45:57 PDT 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12496

           Summary: __traits(parent, x) returns incorrect type
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: slavo5150 at yahoo.com


--- Comment #0 from Mike <slavo5150 at yahoo.com> 2014-03-30 22:45:55 PDT ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list