Skip to content

Commit

Permalink
Fix #4274 - don’t ignore mixed union in array_shift operation
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Oct 12, 2020
1 parent dfa8854 commit 662e2ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/ArrayFunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,17 @@ function thing() {
$list = array_filter($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) {}
}'
],
];
}

Expand Down

0 comments on commit 662e2ea

Please sign in to comment.