Skip to content

Commit d5a5dc8

Browse files
committed
Use BINARY_OP macro for printing Pipe AST.
1 parent a264deb commit d5a5dc8

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Zend/tests/pipe_operator/ast.phpt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ function _test(int $a): int {
77
return $a + 1;
88
}
99

10+
function abool(int $x): bool {
11+
return false;
12+
}
13+
1014
try {
1115
assert((5 |> '_test') == 99);
1216
} catch (AssertionError $e) {
@@ -19,7 +23,14 @@ try {
1923
echo $e->getMessage(), PHP_EOL;
2024
}
2125

26+
try {
27+
assert(5 |> abool(...));
28+
} catch (AssertionError $e) {
29+
echo $e->getMessage(), PHP_EOL;
30+
}
31+
2232
?>
2333
--EXPECTF--
24-
assert(5 |> '_test' == 99)
25-
assert(5 |> _test(...) == 99)
34+
assert((5 |> '_test') == 99)
35+
assert((5 |> _test(...)) == 99)
36+
assert(5 |> abool(...))

Zend/zend_ast.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
22962296
case ZEND_AST_GREATER_EQUAL: BINARY_OP(" >= ", 180, 181, 181);
22972297
case ZEND_AST_AND: BINARY_OP(" && ", 130, 130, 131);
22982298
case ZEND_AST_OR: BINARY_OP(" || ", 120, 120, 121);
2299+
case ZEND_AST_PIPE: BINARY_OP(" |> ", 130, 130, 131);
22992300
case ZEND_AST_ARRAY_ELEM:
23002301
if (ast->child[1]) {
23012302
zend_ast_export_ex(str, ast->child[1], 80, indent);
@@ -2506,11 +2507,6 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
25062507
zend_ast_export_name(str, ast->child[1], 0, indent);
25072508
}
25082509
break;
2509-
case ZEND_AST_PIPE:
2510-
zend_ast_export_ex(str, ast->child[0], 0, indent);
2511-
smart_str_appends(str, " |> ");
2512-
zend_ast_export_ex(str, ast->child[1], 0, indent);
2513-
break;
25142510
case ZEND_AST_NAMED_ARG:
25152511
smart_str_append(str, zend_ast_get_str(ast->child[0]));
25162512
smart_str_appends(str, ": ");

0 commit comments

Comments
 (0)