mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Merge pull request #9651 from tuqqu/array-flip-non-empty-fix
Fix `array_flip` to preserve non-empty array type
This commit is contained in:
commit
6834f5dca1
@ -122,7 +122,7 @@ function array_diff_assoc(array $array, array ...$arrays)
|
||||
*
|
||||
* @param array<TKey, TValue> $array
|
||||
*
|
||||
* @return array<TValue, TKey>
|
||||
* @return ($array is non-empty-array ? non-empty-array<TValue, TKey> : array<TValue, TKey>)
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_flip(array $array)
|
||||
|
@ -2574,6 +2574,17 @@ class ArrayFunctionCallTest extends TestCase
|
||||
takes_non_empty_int_array(array_unique([(object)[]]));
|
||||
',
|
||||
],
|
||||
'arrayFlipPreservesNonEmptyInput' => [
|
||||
'code' => '<?php
|
||||
/** @param non-empty-array<string, int> $input */
|
||||
function takes_non_empty_array(array $input): void {}
|
||||
|
||||
$array = ["hi", "there"];
|
||||
$flipped = array_flip($array);
|
||||
|
||||
takes_non_empty_array($flipped);
|
||||
',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -2865,6 +2876,15 @@ class ArrayFunctionCallTest extends TestCase
|
||||
',
|
||||
'error_message' => 'ArgumentTypeCoercion',
|
||||
],
|
||||
'arrayFlipPreservesEmptyInput' => [
|
||||
'code' => '<?php
|
||||
/** @param non-empty-array<string, int> $input */
|
||||
function takes_non_empty_array(array $input): void {}
|
||||
|
||||
takes_non_empty_array(array_flip([]));
|
||||
',
|
||||
'error_message' => 'InvalidArgument',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user