1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #4274 - don’t ignore mixed union in array_shift operation

This commit is contained in:
Matt Brown 2020-10-12 15:16:47 -04:00 committed by Daniil Gentili
parent 6e3546d900
commit 78380c591b
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 12 additions and 0 deletions

View File

@ -33,6 +33,7 @@ class ArrayPopReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionReturnTyp
$first_arg_array = $first_arg $first_arg_array = $first_arg
&& ($first_arg_type = $statements_source->node_data->getType($first_arg)) && ($first_arg_type = $statements_source->node_data->getType($first_arg))
&& $first_arg_type->hasType('array') && $first_arg_type->hasType('array')
&& !$first_arg_type->hasMixed()
&& ($array_atomic_type = $first_arg_type->getAtomicTypes()['array']) && ($array_atomic_type = $first_arg_type->getAtomicTypes()['array'])
&& ($array_atomic_type instanceof Type\Atomic\TArray && ($array_atomic_type instanceof Type\Atomic\TArray
|| $array_atomic_type instanceof Type\Atomic\TKeyedArray || $array_atomic_type instanceof Type\Atomic\TKeyedArray

View File

@ -1847,6 +1847,17 @@ class ArrayFunctionCallTest extends TestCase
$list = array_filter($list); $list = array_filter($list);
if (!empty($list)) {}' if (!empty($list)) {}'
], ],
'arrayShiftOnMixedOrEmptyArray' => [
'<?php
/**
* @param mixed|array<empty, empty> $lengths
*/
function doStuff($lengths): void {
/** @psalm-suppress MixedArgument, MixedAssignment */
$length = array_shift($lengths);
if ($length !== null) {}
}'
],
]; ];
} }