diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php index 9358bf55142..b785e05b911 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php @@ -33,6 +33,7 @@ public static function getFunctionReturnType( $first_arg_array = $first_arg && ($first_arg_type = $statements_source->node_data->getType($first_arg)) && $first_arg_type->hasType('array') + && !$first_arg_type->hasMixed() && ($array_atomic_type = $first_arg_type->getAtomicTypes()['array']) && ($array_atomic_type instanceof Type\Atomic\TArray || $array_atomic_type instanceof Type\Atomic\TKeyedArray diff --git a/tests/ArrayFunctionCallTest.php b/tests/ArrayFunctionCallTest.php index 339c379053b..7560f6400e6 100644 --- a/tests/ArrayFunctionCallTest.php +++ b/tests/ArrayFunctionCallTest.php @@ -1847,6 +1847,17 @@ function thing() { $list = array_filter($list); if (!empty($list)) {}' ], + 'arrayShiftOnMixedOrEmptyArray' => [ + ' $lengths + */ + function doStuff($lengths): void { + /** @psalm-suppress MixedArgument, MixedAssignment */ + $length = array_shift($lengths); + if ($length !== null) {} + }' + ], ]; }