[php-src] PR #18500: feat: allow multiline arrow functions
| From: | xepozz | Date: | Sun, 04 May 2025 19:49:03 +0000 |
| Subject: | [php-src] PR #18500: feat: allow multiline arrow functions | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-31620@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/18500
Author: xepozz
I've played with the lexer and complete the multiline arrow functions.
Implementation is quite simple:
- old way with no
{}
- new way with {}, like the regular functions
Key points:
- Returning from the arrow function means returning the result to the function point, not to the
parent constructions
- It should work the same way, because the old way to use arrow function used emulated
RETURN ast node, which is similar to fn() => return, but it's not
acceptable by the lexer. I didn't change that, just added a new way to allow multiline
statements.
The last think I don't know how to solve is #7900 issue:
```php
try {
assert((fn(): never => {
return 42;
}) && false);
} catch (\Error $e) {
echo $e->getMessage(), "\n";
}
```
Isn't handled by the catch, 'cause it leads to a Fatal error.
Although, it looks correct because there is no RETURN token added implicitly
@iluuu1994 I remember you've preparing long arrow functions and match expressions, but I think
it can be added separately, so I can reference your RFC if I go to there. What do you think?