[Issue 23972] class identity check is broken

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 20 01:04:19 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23972

--- Comment #5 from Bolpat <qs.il.paperinik at gmail.com> ---
(In reply to Dennis from comment #4)
> I think the spec is wrong (or too vague) here. The interface object has a
> slightly different address than the class object, so the pointers aren't
> equal.
> `is` should be a simple bit compare, and not be doing casting logic for
> classes.

No, in this case, it shouldn't. If one actually wants to compare the pointer
values, one can always cast to `void*` and compare the pointers. The fact that
the class handles are represented by pointers is really an implementation
detail. The current behavior is both surprising and useless. If the `is`
operator does not provide class object identity, it should not be there at all;
the error message in that case could point out that an explicit cast to Object
is needed, but if that's what programmers will do anyways, why not provide
something like an operator for it that does The Right Thing™?

--


More information about the Digitalmars-d-bugs mailing list