Bug 10806 – Interface covariance for more than one interface at once also broken

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-11T22:36:01Z
Last change time
2019-03-30T09:03:56Z
Keywords
pull
Assigned to
No Owner
Creator
FeepingCreature
Blocks
10785

Comments

Comment #0 by default_357-line — 2013-08-11T22:36:01Z
After bug 10785, Infiltrator on #d simplified the testcase a lot. http://dpaste.dzfl.pl/e9df03f9 Whatever DMD is doing to convert object types to interface types for covariant interface inheritance, it seems to always use the first interface that is being implemented with an override, even when emitting the vtable for the second one.
Comment #1 by lt.infiltrator — 2013-08-11T23:03:56Z
Code and output for easy perusal. ---------------------- 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
Comment #2 by js.mdnq — 2013-08-21T18:52:03Z
Additional example: http://dpaste.dzfl.pl/a390f1f4
Comment #3 by default_357-line — 2013-08-22T01:54:04Z
> Additional example: > > http://dpaste.dzfl.pl/a390f1f4 That's not the same bug. The only issue with that code is that the compiler fails to warn you that the call to foo() is ambiguous.
Comment #4 by default_357-line — 2019-03-29T14:02:14Z
This problem still exists on master. To demonstrate why it's a problem: import std.stdio; interface A1 { A1 foo(); } interface A2 { A2 foo(); void bar(); } class C1 : A1, A2 { override C1 foo() { return new C1; } override void bar() { writefln("bar"); } } void main() { A2 x = new C1; A2 y = x.foo(); writefln("X: %s", x.classinfo); writefln("Y: %s", y.classinfo); y.bar(); } Note that "A2 y" has an A1 vtable.
Comment #5 by dlang-bot — 2019-03-29T14:51:59Z
@FeepingCreature created dlang/dmd pull request #9515 "Fix issue 10806: check every interface for covariance, not just the first" fixing this issue: - Fix issue 10806: check every interface for covariance, not just the first https://github.com/dlang/dmd/pull/9515
Comment #6 by dlang-bot — 2019-03-30T09:03:56Z
dlang/dmd pull request #9515 "Fix issue 10806: check every interface for covariance, not just the first" was merged into master: - 175de6781a1b199c318b25db5494619ada84102c by Mathis Beer: Fix issue 10806: check every interface for covariance, not just the first https://github.com/dlang/dmd/pull/9515