[Issue 19633] New: Identity expression produces wrong result with interface inheritance
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jan 30 01:04:13 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19633
Issue ID: 19633
Summary: Identity expression produces wrong result with
interface inheritance
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dhasenan at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list