Skip to content

Commit bb821e2

Browse files
committed
Fix ReversePipeTransformerVisitor
1 parent 3702305 commit bb821e2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/Parser/ReversePipeTransformerVisitor.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ public function enterNode(Node $node): ?Node
1717
$attributes = $node->getAttributes();
1818
$origPipeAttributes = $attributes[PipeTransformerVisitor::ORIGINAL_PIPE_ATTRIBUTE_NAME] ?? [];
1919
if ($origPipeAttributes !== [] && count($node->getArgs()) === 1) {
20-
unset($attributes[PipeTransformerVisitor::ORIGINAL_PIPE_ATTRIBUTE_NAME]);
20+
if ($node->name instanceof Node\Name) {
21+
unset($attributes[PipeTransformerVisitor::ORIGINAL_PIPE_ATTRIBUTE_NAME]);
22+
return new Node\Expr\BinaryOp\Pipe(
23+
$node->getArgs()[0]->value,
24+
new Node\Expr\FuncCall($node->name, [new Node\VariadicPlaceholder()], attributes: $attributes),
25+
attributes: $origPipeAttributes,
26+
);
27+
}
28+
2129
return new Node\Expr\BinaryOp\Pipe(
2230
$node->getArgs()[0]->value,
23-
new Node\Expr\FuncCall($node->name, [new Node\VariadicPlaceholder()], attributes: $attributes),
31+
$node->name,
2432
attributes: $origPipeAttributes,
2533
);
2634
}

tests/PHPStan/Analyser/nsrt/pipe-operator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ public function doArrayMap(array $ints): void
113113
});
114114

115115
assertType('array<int<1, max>>', $ints |> function (array $x) {
116-
assertType('array<int<1, max>>', $x);
117-
return array_map(function (int $i) {
118-
assertType('int<1, max>', $i);
116+
assertType('array<int<1, max>>', $x);
117+
return array_map(function (int $i) {
118+
assertType('int<1, max>', $i);
119119

120-
return $i;
121-
}, $x);
122-
});
120+
return $i;
121+
}, $x);
122+
});
123123
}
124124

125125
/**

0 commit comments

Comments
 (0)