what if return returned subclasses
Adam D Ruppe
destructionator at gmail.com
Wed Oct 20 22:42:43 UTC 2021
ok consider this:
Object identity(return Object o) { return o; }
Subclass s = identity(new Subclass());
That is, it is converted to the base class before passed to the
function, but since it is marked `return` anyway, the compiler
knows it is the same instance, so the static type passed in is
retained in the return value. So it is kinda like type erased but
then repainted back on.
Would this break anything? There's a few OOP patterns that might
be made a lil nicer if this just worked.
More information about the Digitalmars-d
mailing list