From 4960d304a5c3a62522e48a006c3c6d708a64fdd5 Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Wed, 28 May 2025 20:40:20 +0300 Subject: [PATCH 1/4] fix: add parentheses to ast functions dump --- Zend/tests/arrow_functions/007.phpt | 6 ++---- Zend/tests/enum/ast-dumper.phpt | 4 ++-- Zend/tests/functions/007.phpt | 18 ++++++++++++++++++ Zend/tests/match/009_ast_export.phpt | 4 ++-- Zend/zend_ast.c | 9 ++++++++- 5 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 Zend/tests/functions/007.phpt diff --git a/Zend/tests/arrow_functions/007.phpt b/Zend/tests/arrow_functions/007.phpt index ec1e165fd680d..66b03b84c2e93 100644 --- a/Zend/tests/arrow_functions/007.phpt +++ b/Zend/tests/arrow_functions/007.phpt @@ -5,8 +5,6 @@ zend.assertions=1 --FILE-- 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 diff --git a/Zend/tests/enum/ast-dumper.phpt b/Zend/tests/enum/ast-dumper.phpt index ed38e44e7c2f2..7972fe64965e2 100644 --- a/Zend/tests/enum/ast-dumper.phpt +++ b/Zend/tests/enum/ast-dumper.phpt @@ -28,7 +28,7 @@ try { ?> --EXPECT-- -assert(function () { +assert((function () { enum Foo { case Bar; } @@ -45,4 +45,4 @@ assert(function () { } return false; -}()) +})()) diff --git a/Zend/tests/functions/007.phpt b/Zend/tests/functions/007.phpt new file mode 100644 index 0000000000000..0d741546dc63b --- /dev/null +++ b/Zend/tests/functions/007.phpt @@ -0,0 +1,18 @@ +--TEST-- +Pretty printing for arrow functions +--INI-- +zend.assertions=1 +--FILE-- +getMessage(), ' failed', PHP_EOL; +} + +?> +--EXPECT-- +assert(): assert((function () { + return false; +})()) failed diff --git a/Zend/tests/match/009_ast_export.phpt b/Zend/tests/match/009_ast_export.phpt index 8dc89d4fe0672..9d95b722b2229 100644 --- a/Zend/tests/match/009_ast_export.phpt +++ b/Zend/tests/match/009_ast_export.phpt @@ -19,10 +19,10 @@ assert((function () { ?> --EXPECTF-- -assert(): assert(function () { +assert(): assert((function () { match ('foo') { 'foo', 'bar' => false, 'baz' => 'a', default => 'b', }; -}()) failed +})()) failed diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 5350037362294..d2156f0fdceb3 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -2233,7 +2233,14 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio 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); + 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, ')'); From b4110e3f78873d81dff517bd05ef8cc910248779 Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Wed, 28 May 2025 21:09:17 +0300 Subject: [PATCH 2/4] fix: "Label followed by a declaration is a C23 extension" warn --- Zend/zend_ast.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index d2156f0fdceb3..ba5eeaa5d572b 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -2232,7 +2232,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio smart_str_appends(str, "::$"); zend_ast_export_var(str, ast->child[1], 0, indent); break; - case ZEND_AST_CALL: + 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, "("); @@ -2245,6 +2245,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio 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, '('); From fe1571487aa6be2befac123f5d92b6d5343dedd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 29 May 2025 13:56:32 +0200 Subject: [PATCH 3/4] NEWS --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 557fe0aea7f25..93c0b33550223 100644 --- a/NEWS +++ b/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. (Dmitriy Derepko) - Curl: . Added curl_multi_get_handles(). (timwolla) From f1d14934799cf0530123f02e84f346027a137d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 29 May 2025 13:59:42 +0200 Subject: [PATCH 4/4] Update contributor name in NEWS Co-authored-by: Dmitrii Derepko --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 93c0b33550223..c0f20b747da2d 100644 --- a/NEWS +++ b/NEWS @@ -52,7 +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. (Dmitriy Derepko) + . Fixed AST printing for immediately invoked Closure. (Dmitrii Derepko) - Curl: . Added curl_multi_get_handles(). (timwolla)