From fe036d4db0f5d3ae9af7a83d6fe38195779a8d26 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Thu, 6 Jan 2022 10:38:58 +0200 Subject: [PATCH] Prevent crashes on `array_map(...)` Fixes vimeo/psalm#7305 --- .../Internal/PhpVisitor/Reflector/ExpressionScanner.php | 4 ++++ tests/ClosureTest.php | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php index 6e88891a20a..2a6dbf71eb9 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php @@ -125,6 +125,10 @@ private static function registerClassMapFunctionCall( } } + if ($node->isFirstClassCallable()) { + return; + } + if ($function_id === 'define') { $first_arg_value = isset($node->getArgs()[0]) ? $node->getArgs()[0]->value : null; $second_arg_value = isset($node->getArgs()[1]) ? $node->getArgs()[1]->value : null; diff --git a/tests/ClosureTest.php b/tests/ClosureTest.php index 64a17a53d28..f0ca9bb1fe5 100644 --- a/tests/ClosureTest.php +++ b/tests/ClosureTest.php @@ -729,6 +729,12 @@ public static function __callStatic(string $name, array $args): mixed { [], '8.1' ], + 'FirstClassCallable:array_map' => [ + ' [], + [], + '8.1', + ], ]; } @@ -1171,9 +1177,8 @@ public static function __callStatic(string $name, array $args): mixed { 'error_message' => 'MixedAssignment', [], false, - '8.1' + '8.1', ], - ]; } }