[Issue 10785] New: Interface diamond covariance causes silent breakage

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 8 17:01:54 PDT 2013


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

           Summary: Interface diamond covariance causes silent breakage
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: default_357-line at yahoo.de


--- Comment #0 from FeepingCreature <default_357-line at yahoo.de> 2013-08-08 17:01:53 PDT ---
Consider this code:

interface A { A foo(); }

interface A1 : A { A1 foo(); }
interface A2 : A { A2 foo(); }

class C : A1, A2 {
  override C foo() { return new C; }
}

void main() {
  A2 x = new C;
  A2 y = x.foo();
  // y.classinfo.name should be "A2" here; instead, it is "A1". The vtables
also don't match up (not that there's significant vtables in this example, but,
you know)
  assert(y.classinfo.name.find("A2") != -1); // fails
  // Further issues: this should be a no-op, but it isn't.
  A2 z = cast(A2) cast(A) y;
  assert(z.classinfo.name == y.classinfo.name); // fails too
}

The problem seems to be that whatever magic the compiler does to make interface
covariance work fails in the case where it has to satisfy the same interface
via two covariant child interfaces at once. I suspect this would either require
A2.foo to be filled with a stub that does the conversion of C to A2, or a
compiletime error.

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