Skip to content

Commit b226ace

Browse files
committed
Make the output version of the pipe AST look like a pipe, not the desugared version.
1 parent 36f0e75 commit b226ace

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

Zend/tests/pipe_operator/ast.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Test that a pipe operator displays as a pipe operator when outputting syntax.
3+
--FILE--
4+
<?php
5+
6+
function _test(int $a): int {
7+
return $a + 1;
8+
}
9+
10+
assert((5 |> '_test') == 99);
11+
12+
?>
13+
--EXPECTF--
14+
Warning: assert(): assert(5 |> \_test == 99) failed in %s on line %d

Zend/zend_ast.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,10 +1707,17 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
17071707
zend_ast_export_var(str, ast->child[1], 0, indent);
17081708
break;
17091709
case ZEND_AST_CALL:
1710-
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
1711-
smart_str_appendc(str, '(');
1712-
zend_ast_export_ex(str, ast->child[1], 0, indent);
1713-
smart_str_appendc(str, ')');
1710+
if (ast->attr & ZEND_CALL_SYNTAX_PIPE) {
1711+
zend_ast_export_ex(str, ast->child[1], 0, indent);
1712+
smart_str_appends(str, " |> ");
1713+
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
1714+
}
1715+
else {
1716+
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
1717+
smart_str_appendc(str, '(');
1718+
zend_ast_export_ex(str, ast->child[1], 0, indent);
1719+
smart_str_appendc(str, ')');
1720+
}
17141721
break;
17151722
case ZEND_AST_CLASS_CONST:
17161723
zend_ast_export_ns_name(str, ast->child[0], 0, indent);

0 commit comments

Comments
 (0)