Bug 11178 – Class may implement same interface multiple times with different interface pointers, breaking (a is b) semantics

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-05T16:27:00Z
Last change time
2015-06-09T05:11:43Z
Assigned to
nobody
Creator
default_357-line

Comments

Comment #0 by default_357-line — 2013-10-05T16:27:12Z
Consider https://gist.github.com/6847299 . The errant behavior goes away if you remove the I2 inheritance from C2, indicating that C2 implements I2 _twice_ with different interface pointers. This leads to hilariously hard-to-find errors, since one generally assumes that casting two objects to the same interface makes them is-comparable if they're the same object. The second I2 in C2 should either be made illegal or silently ignored.
Comment #1 by ibuclaw — 2013-11-17T07:55:43Z
Pasting in test case in comments just incase gist.github removes the pastebin. =) module testcase; import std.stdio; interface I1 { } interface I2 : I1 { } class C1 : I2 { void foo() { writefln("These should REALLY not be the same:"); writefln(": %s", cast(void*) cast(I2) cast(I1) this); writefln(": %s", cast(void*) cast(I2) this); writefln("for comparison"); Object obj = cast(Object) this; writefln(": %s", cast(void*) cast(I2) cast(I1) obj); writefln(": %s", cast(void*) cast(I2) obj); } } class C2 : C1, I2 { } void main() { (new C2).foo(); }
Comment #2 by default_357-line — 2013-11-18T03:53:16Z
Of course, I meant to say "These should REALLY be the same" there. Typo, sorry.
Comment #3 by verylonglogin.reg — 2013-12-04T08:52:31Z
*** This issue has been marked as a duplicate of issue 4979 ***