From 78380c591b57fb68791cb8db784837334779a591 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Mon, 12 Oct 2020 15:16:47 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20#4274=20-=20don=E2=80=99t=20ignore=20mixe?= =?UTF-8?q?d=20union=20in=20array=5Fshift=20operation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReturnTypeProvider/ArrayPopReturnTypeProvider.php | 1 + tests/ArrayFunctionCallTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+) 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) {} + }' + ], ]; }