Skip to content

Commit 9454821

Browse files
committed
Fix "Arrow functions on the right hand side of |> must be parenthesized" for clone(...)
1 parent b3c7d7b commit 9454821

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/php/lang/ast/emit/RewriteCallables.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait RewriteCallables {
1313

1414
protected function emitCallable($result, $callable) {
1515
if ($callable->expression instanceof Literal && 'clone' === $callable->expression->expression) {
16-
$result->out->write('fn($o) => clone $o');
16+
$result->out->write('(fn($o) => clone $o)');
1717
} else {
1818
$this->emitPartial($result, $callable);
1919
}

src/test/php/lang/ast/unittest/emit/CallableSyntaxTest.class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ public function run() {
228228
Assert::equals('cba', $f('abc'));
229229
}
230230

231+
#[Test]
232+
public function clone() {
233+
$handles= $this->run('use lang\ast\unittest\emit\Handle; class %T {
234+
public function run() {
235+
$a= new Handle(0);
236+
return [$a, $a |> clone(...)];
237+
}
238+
}');
239+
$handles[1]->redirect(4);
240+
Assert::notEquals($handles[0], $handles[1]);
241+
}
242+
231243
#[Test]
232244
public function partial_function_application() {
233245
$f= $this->run('class %T {

0 commit comments

Comments
 (0)