dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Enhancement: `Base(child)` class object upcast

Open ntrel opened this issue 3 months ago • 8 comments

FundamentalType(arg) works, e.g. int(2).

Enum(Enum.foo) works, which does nothing - see compilable/b16346.d below and/or https://issues.dlang.org/show_bug.cgi?id=16346.

Let's allow class instance upcasting without having to use cast - Base(child). cast can be bug-prone, and upcasting is always fine. In generic code it's not always clear what a type resolves to, so avoiding cast makes code reviews easier.

Here upcasting takes precedence over a static opCall, but that could be swapped.

ntrel avatar Apr 29 '24 16:04 ntrel