mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 12:24:49 +01:00
Fix array_flip to preserve non-empty array type
This commit is contained in:
parent
cb6508e63c
commit
d3a21acc24
@ -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)
|
||||
|
@ -2549,6 +2549,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);
|
||||
',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -2840,6 +2851,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