On 1. 4. 2021 19:24:35, Bruce Weirdan <weirdan@gmail.com> wrote:
> Since throw is an expression (since PHP 8.0,
> https://wiki.php.net/rfc/throw_expression), it
> must have a type for its
> result,
> as any expression has a type. And it's result is exactly noreturn (or
> never, as this option seems to be preferred
> judging by current vote results), because throw never returns.
>
> It's quite natural to extend that to function calls that never return as
> well. And then it makes sense to declare that type
> as a part of function signature like you can do with other types.
>
> --
> Best regards,
> Bruce Weirdan mailto:
> weirdan@gmail.com
>
Yes, this works very well in the typesystem. For example if we define the
type of the match expression as a union of all its arms, then the arm that
always throws or contains exit() has the noreturn/never type, which is
thrown away in a union (int|string|never can be normalized to int|string).