[php-src] Issue #7900: `never` return type for arrow functions with throw expressions

From: Date: Fri, 07 Jan 2022 11:55:09 +0000
Subject: [php-src] Issue #7900: `never` return type for arrow functions with throw expressions
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238848@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7900
Comment Author: iluuu1994

PHP adds an implicit return to arrow functions.

https://github.com/php/php-src/blob/266667c23425a139edb4f44d0f42a99186520e43/Zend/zend_language_parser.y#L1209-L1215

We could of course not add that implicit return for never. In that case the arrow
function would simplify throw if the end of the function is reached without throwing/exiting, just
like normal never functions do. I wouldn't classify this as a bug though.

> Would this also apply to functions returning void? https://3v4l.org/YkVBg

Yes, theoretically we could do the same here, although it's more controversial. E.g.

```php
// Makes sense, inner function returns void (NULL), outer function returns
void too
fn (): void => voidFn()
// Makes sense, inner function might have desired side effects but result is not needed
fn (): void => nonVoidFn()
// Not useful, any side-effect free expression that has no purpose is discarded
fn (): void => 42
```

That said, this change would at least require a mail to the mailing list and likely an RFC as
historically there have been quite a few disagreements with how void/never
should behave.


Thread (1 message)

  • iluuu1994
« previous php.bugs (#238848) next »