Comment #0 by verylonglogin.reg — 2013-12-04T09:12:28Z
Because of Issue 4979 implementing an interface twice results in different references dependent on cast order.
Currently Identity Expression over two `interface`s just compare pointers and
over an `interface` and a `class` it adds a constant dependent on operands CT
types to `class` reference and then compare pointers:
---
interface I {}
class A: I {}
class B: A, I {}
void main() @safe
{
B b = new B;
A a = b;
I ia = a, ib = b;
assert(ia is a); // ok
assert(ib is b); // ok
assert(ia is b); // fails
assert(ib is a); // fails
assert(ia is ib); // fails
}
---
Thus Identity Expression has nothing to do with "the object references are for
the same object" except the case of two classes unless Issue 4979 is fixed.
If Issue 4979 isn't going to be fixed in the immediate future Identity
Expression over `interface`s should be appropriately documented and possibly
deprecated.
Comment #1 by robert.schadek — 2024-12-15T15:22:28Z