mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
zend_ast: Add parentheses around IIFE in zend_ast_export() (#18688)
This commit is contained in:
parent
399cb4ca85
commit
fdebad0b25
6 changed files with 35 additions and 10 deletions
1
NEWS
1
NEWS
|
@ -52,6 +52,7 @@ PHP NEWS
|
|||
. Fixed bugs GH-17711 and GH-18022 (Infinite recursion on deprecated attribute
|
||||
evaluation) and GH-18464 (Recursion protection for deprecation constants not
|
||||
released on bailout). (DanielEScherzer and ilutov)
|
||||
. Fixed AST printing for immediately invoked Closure. (Dmitrii Derepko)
|
||||
|
||||
- Curl:
|
||||
. Added curl_multi_get_handles(). (timwolla)
|
||||
|
|
|
@ -5,8 +5,6 @@ zend.assertions=1
|
|||
--FILE--
|
||||
<?php
|
||||
|
||||
// TODO We're missing parentheses for the direct call
|
||||
|
||||
try {
|
||||
assert((fn() => false)());
|
||||
} catch (AssertionError $e) {
|
||||
|
@ -21,5 +19,5 @@ try {
|
|||
|
||||
?>
|
||||
--EXPECT--
|
||||
assert(): assert(fn() => false()) failed
|
||||
assert(): assert(fn&(int ...$args): ?bool => $args[0](false)) failed
|
||||
assert(): assert((fn() => false)()) failed
|
||||
assert(): assert((fn&(int ...$args): ?bool => $args[0])(false)) failed
|
||||
|
|
|
@ -28,7 +28,7 @@ try {
|
|||
|
||||
?>
|
||||
--EXPECT--
|
||||
assert(function () {
|
||||
assert((function () {
|
||||
enum Foo {
|
||||
case Bar;
|
||||
}
|
||||
|
@ -45,4 +45,4 @@ assert(function () {
|
|||
}
|
||||
|
||||
return false;
|
||||
}())
|
||||
})())
|
||||
|
|
18
Zend/tests/functions/007.phpt
Normal file
18
Zend/tests/functions/007.phpt
Normal file
|
@ -0,0 +1,18 @@
|
|||
--TEST--
|
||||
Pretty printing for arrow functions
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
try {
|
||||
assert((function() { return false; })());
|
||||
} catch (AssertionError $e) {
|
||||
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
assert(): assert((function () {
|
||||
return false;
|
||||
})()) failed
|
|
@ -19,10 +19,10 @@ assert((function () {
|
|||
|
||||
?>
|
||||
--EXPECTF--
|
||||
assert(): assert(function () {
|
||||
assert(): assert((function () {
|
||||
match ('foo') {
|
||||
'foo', 'bar' => false,
|
||||
'baz' => 'a',
|
||||
default => 'b',
|
||||
};
|
||||
}()) failed
|
||||
})()) failed
|
||||
|
|
|
@ -2424,12 +2424,20 @@ simple_list:
|
|||
smart_str_appends(str, "::$");
|
||||
zend_ast_export_var(str, ast->child[1], 0, indent);
|
||||
break;
|
||||
case ZEND_AST_CALL:
|
||||
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
|
||||
case ZEND_AST_CALL: {
|
||||
zend_ast *left = ast->child[0];
|
||||
if (left->kind == ZEND_AST_ARROW_FUNC || left->kind == ZEND_AST_CLOSURE) {
|
||||
smart_str_appends(str, "(");
|
||||
zend_ast_export_ns_name(str, left, 0, indent);
|
||||
smart_str_appends(str, ")");
|
||||
} else {
|
||||
zend_ast_export_ns_name(str, left, 0, indent);
|
||||
}
|
||||
smart_str_appendc(str, '(');
|
||||
zend_ast_export_ex(str, ast->child[1], 0, indent);
|
||||
smart_str_appendc(str, ')');
|
||||
break;
|
||||
}
|
||||
case ZEND_AST_PARENT_PROPERTY_HOOK_CALL:
|
||||
smart_str_append(str, Z_STR_P(zend_ast_get_zval(ast->child[0])));
|
||||
smart_str_appendc(str, '(');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue