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



--- Comment #15 from Haruki Shigemori <rayerd....@gmail.com> 2011-09-17 
09:04:50 PDT ---
import std.stdio;

class Base  {}
class Derived : Base {}

class X
{
    Base foo() { return new Base; }
}
class Y : X
{
    Derived foo() { return new Derived; }
}

void main()
{
    // Covariance is good
    {
        Base delegate() f = delegate Derived() { return new Derived; };
        writefln("delegate convariance is <%s>", f().toString() == "a.Derived"
? "OK" : "NG");
    }{
        static Derived fp() { return new Derived; }
        Base function() f = &fp;
        writefln("function pointer covariance is <%s>", f().toString() ==
"a.Derived" ? "OK" : "NG");
    }

    // Contravariance is BAD
    {
        auto c = new class { void foo(Base){} };

        // GOOD
        void delegate(Base) f = &c.foo;
        f(new Base);
        f(new Derived);

        // BAD
        void delegate(Derived) g = &c.foo;
        g(new Derived);
    }
}

a.d(33): Error: cannot implicitly convert expression (&c.foo) of type void
delegate(Base) to void delegate(Derived)

---

Why is "Status" "RESOLVED-FIXED"?

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

Reply via email to