Hey Aleksander,

On Thu, Mar 11, 2021 at 8:25 AM Aleksander Machniak <a...@alec.pl> wrote:

> On 10.03.2021 20:28, Ben Ramsey wrote:
> >> I don't like that type covariance would be allowed. Why such an
> >> exception to the rules?
> >
> > It’s not an exception. Returns are covariant. Parameters are
> > contravariant. Since `noreturn` is a subtype of all other types, it
> > behaves as expected.
>
> I see it's a subtype, I don't get why. Wouldn't it be better to be a
> separate type so return type covariance is not allowed (as it is with
> void)? Was it a design decision or a side product of the implementation?
>

`noreturn` is what's called the "bottom type", and it's a subtype of all
types.
It can sound counter-intuitive, but it is true that all methods in a
subclass can be re-implemented with the bottom type as their return type
(instead of their original one), and the system is still sound from a type
perspective.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

Reply via email to