On Wed, 10 Mar 2021 at 16:04, Kamil Tekiela <tekiela...@gmail.com> wrote:

> I am concerned with some edge cases. What if a function both returns and
> throws at the same time? For example:
>
> function a():noreturn {
>     return throw new Exception('Boom!');
> }
>
> or
>
> function a():noreturn {
> try {
> throw new Exception('Boom!');
> } finally {
>         return;
>     }
> }
>

In both cases those are compile-time errors, since no return is allowed in
a function that has the noreturn type.

I've added both as tests (
https://github.com/php/php-src/pull/6761/commits/56ae52e84da5c063c28ba7739ac15979e61afc91)
but I don't _think_ it's necessary to mention it in the PR given how much
of an edge-case it is.


> Also, the message "TypeError: a(): Nothing was expected to be returned" is
> inaccurate. It should say that the function should terminate instead of
> returning. It's also not a TypeError if no value is expected. At the moment
> it sounds like we need to make the function somehow return nothing.
>

It's a TypeError because noreturn is a type, but I agree the error message
could be improved.

Ilija suggested "noreturn function was expected to throw, terminate or run
infinitely" and I'd welcome other suggestions.


> If we are to bikeshed about the name then we might also consider other
> possibilities: None, Nothing, Returnless
>

I'd prefer to stick to noreturn and never, which have plenty of precedent
in other languages' type systems.

Reply via email to