[Issue 4182] New: alias of base function does not transfer covariance

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 13 05:12:38 PDT 2010


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

           Summary: alias of base function does not transfer covariance
           Product: D
           Version: 2.041
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: schveiguy at yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy at yahoo.com> 2010-05-13 05:12:30 PDT ---
This should compile:

interface I
{
    I foo();
    alias foo bar;
}

class C : I
{
    C foo() { return this; }
}

void main()
{
    auto c = new C;
    c = c.bar();
}

But it doesn't, because for some reason, the compiler inserts a cast:

Error: cannot implicitly convert expression ((cast(I)c).foo()) of type
aliascovariance.I to aliascovariance.C

Change I to a class, and the error is even more weird:

Error: cannot implicitly convert expression (c.foo()) of type aliascovariance.I
to aliascovariance.C

As a workaround, you can repeat the alias in the derived class.

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


More information about the Digitalmars-d-bugs mailing list