diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php index 7b9578c960d..9019f4f4471 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\ObjectLike diff --git a/tests/ArrayFunctionCallTest.php b/tests/ArrayFunctionCallTest.php index 4b4565071c5..56f88e384de 100644 --- a/tests/ArrayFunctionCallTest.php +++ b/tests/ArrayFunctionCallTest.php @@ -1848,6 +1848,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) {} + }' + ], ]; }