Restriction on interface function types

Steve Teale steve.teale at britseyeview.com
Wed Mar 12 06:05:05 PDT 2014


On Wednesday, 12 March 2014 at 11:13:00 UTC, monarch_dodra wrote:
>
> That said, I'd expect this to work:
>
> //----
> interface I
> {
>    I myType();
> }
>
> class A: I
> {
>    //auto myType() { return cast(A) null; } //Nope
>    A myType() { return cast(A) null; } //OK
> }
> //----
>
> Yup, covariance desired, but

import std.stdio;

interface I
{
    I myType();
}

class A: I
{
    A myType() { return cast(A) null; }
    void foo() { writeln("foo"); }
}

void main()
{
    I a = new A();
    writeln(typeof(a.myType()).stringof);
}

returns I

Seems like a bug to me.

Steve



More information about the Digitalmars-d mailing list