www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10785] New: Interface diamond covariance causes silent breakage

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: default_357-line yahoo.de



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: -------
Aug 08 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10785


Infiltrator <lt.infiltrator gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lt.infiltrator gmail.com



PDT ---
This also affects non-diamond configurations:

http://dpaste.dzfl.pl/e9df03f9

----------------------
import std.stdio;

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

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

interface B1 { B1 foo(); }
interface B2 { B2 foo(); }

class C2 : B2, B1 {
  override C2 foo() { return new C2; }
}

void main() {
  A2 x = new C1;
  A2 y = x.foo();
  writefln("X: %s", x.classinfo);
  writefln("Y: %s", y.classinfo);


  B2 a = new C2;
  B2 b = a.foo();
  writefln("A: %s", a.classinfo);
  writefln("B: %s", b.classinfo);
}
-----------------------
Application output:

X: f230.A2
Y: f230.A1
A: f230.B2
B: f230.B2

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 11 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10785




22:40:21 PDT ---

 This also affects non-diamond configurations:
Thanks, filed as 10806. Not sure whether to mark this as a duplicate. (10806 is the more general bug) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 11 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10785




PDT ---

non-diamond is fixed.  Somebody more knowledgeable in dmd can make the
duplicate decision.

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