Bug 19633 – Identity expression produces wrong result with interface inheritance

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-01-30T01:04:13Z
Last change time
2023-12-16T20:28:43Z
Assigned to
No Owner
Creator
Neia Neutuladh

Comments

Comment #0 by dhasenan — 2019-01-30T01:04:13Z
https://dlang.org/spec/expression.html#identity_expressions says: "For class objects, identity is defined as the object references are for the same object. Null class objects can be compared with is." This is one option for comparing two interface references with `is`. Continuing on, there are other obviously inapplicable options, leaving just the default: "For other operand types, identity is defined as being the same as equality." This is another option. Test case: --- interface A {} interface B : A {} class C : A, B {} void main() { A a = new C; B b = cast(B)a; writeln(a is b); // false writeln(cast(Object)a is cast(Object)b); // true writeln(a == b); // true } --- If the first option is chosen, `a is b` should have the same result as `cast(Object)a is cast(Object)b`, which is true. If the second option is chosen, `a is b` should have the same result as `a == b`, which is true.
Comment #1 by b2.temp — 2023-12-16T20:28:43Z
more comments and defunct PR in the newest report *** This issue has been marked as a duplicate of issue 23972 ***