Re: [VOTE] noreturn type

From: Date: Thu, 01 Apr 2021 19:03:03 +0000
Subject: Re: [VOTE] noreturn type
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-113922@lists.php.net to get a copy of this message
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).


Thread (30 messages)

« previous php.internals (#113922) next »