[Issue 4511] New: Contravariance problem

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 26 13:35:13 PDT 2010


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

           Summary: Contravariance problem
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-07-26 13:35:11 PDT ---
A problem found by Jesse Phillips. This is Java program:


class Base {}

class Derived extends Base {}

abstract class Abstract {
    abstract Base foo();
}

class Concrete extends Abstract {
     @Override Derived foo() {
        return new Base();
    }
}

class Test {}



The javac compiler prints:


Test.java:11: incompatible types
        return new Base();
               ^
  required: Derived
  found:    Base
1 error



But dmd 2.047 compiles this D2 program with no errors:

class Base {}

class Derived : Base {}

abstract class Abstract {
    abstract Base foo();
}

class Concrete : Abstract {
    override Derived foo() {
        return new Base;
    }
}

void main() {}

-- 
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