Skip to content

Commit

Permalink
Bail out on list insertion of non-Node
Browse files Browse the repository at this point in the history
PhpStan correctly detected that this is not supported. We could
add support for it, but for now just make sure it doesn't crash.
  • Loading branch information
nikic committed Sep 17, 2022
1 parent b3ad14b commit f7b448f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/PhpParser/PrettyPrinterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,11 @@ protected function pArray(
return null;
}

if (!$arrItem instanceof Node) {
// We only support list insertion of nodes.
return null;
}

// We go multiline if the original code was multiline,
// or if it's an array item with a comment above it.
// Match always uses multiline formatting.
Expand Down
10 changes: 9 additions & 1 deletion test/code/formatPreservation/listInsertion.test
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,12 @@ function test() {
$a;
$b;
$z;
}
}
-----
<?php
list($x, $y) = $z;
-----
array_splice($stmts[0]->expr->var->items, 1, 0, [null]);
-----
<?php
list($x, , $y) = $z;

0 comments on commit f7b448f

Please sign in to comment.