http://d.puremagic.com/issues/show_bug.cgi?id=10197

           Summary: [REG2.063] Cannot cast overloaded template property
                    result
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: [email protected]
        ReportedBy: [email protected]


--- Comment #0 from Kenji Hara <[email protected]> 2013-05-28 23:31:25 PDT ---
From: http://forum.dlang.org/post/[email protected]

This code should work, but doesn't.

template OriginalType(T)
{
    static if (is(T U == enum))
        alias OriginalType = U;
    else
        static assert(0);
}

enum E : int { F = -20 }
struct S
{
    int val;
    @trusted @property T as(T)()
    if (is(T == int) && !is(T == enum))
    {
        return cast(T)(val);
    }
    @trusted @property T as(T)()
    if (is(T == enum))
    {
        return cast(T)as!(OriginalType!T);  // L21
    }
}
void main()
{
    S val = S(-20);
    assert(val.as!int == -20);
    assert(val.as!E == E.F);    // L28
}

output:
test.d(21): Error: cannot cast this.as!(OriginalType!(T))
test.d(28): Error: template instance test.S.as!(E) error instantiating

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

Reply via email to