From f7b448fa1557a2b5943c56da453221ff3e362fff Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 17 Sep 2022 21:14:31 +0200 Subject: [PATCH] Bail out on list insertion of non-Node PhpStan correctly detected that this is not supported. We could add support for it, but for now just make sure it doesn't crash. --- lib/PhpParser/PrettyPrinterAbstract.php | 5 +++++ test/code/formatPreservation/listInsertion.test | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/PhpParser/PrettyPrinterAbstract.php b/lib/PhpParser/PrettyPrinterAbstract.php index 3ee11d98dd..643801dd3f 100644 --- a/lib/PhpParser/PrettyPrinterAbstract.php +++ b/lib/PhpParser/PrettyPrinterAbstract.php @@ -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. diff --git a/test/code/formatPreservation/listInsertion.test b/test/code/formatPreservation/listInsertion.test index 6ddd8168ca..30b129179b 100644 --- a/test/code/formatPreservation/listInsertion.test +++ b/test/code/formatPreservation/listInsertion.test @@ -345,4 +345,12 @@ function test() { $a; $b; $z; -} \ No newline at end of file +} +----- +expr->var->items, 1, 0, [null]); +----- +