mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
parent
d54f9bca17
commit
9b8e8ab964
@ -1,12 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* @psalm-template T as array-key
|
||||
* @psalm-template A as non-empty-array<T, mixed>|array<T, mixed>
|
||||
*
|
||||
* @param array<T, mixed> $arr
|
||||
* @param mixed $search_value
|
||||
* @param bool $strict
|
||||
* @param A $arr
|
||||
* @param mixed $search_value
|
||||
* @param bool $strict
|
||||
*
|
||||
* @return list<T>
|
||||
* @return (A is non-empty-array ? non-empty-list<T> : list<T>)
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_keys(array $arr, $search_value = null, bool $strict = false)
|
||||
|
@ -93,7 +93,7 @@ class FunctionTemplateTest extends TestCase
|
||||
* @template T as array-key
|
||||
*
|
||||
* @param array<T, mixed> $arr
|
||||
* @return array<int, T>
|
||||
* @return list<T>
|
||||
*/
|
||||
function my_array_keys($arr) {
|
||||
return array_keys($arr);
|
||||
@ -101,7 +101,24 @@ class FunctionTemplateTest extends TestCase
|
||||
|
||||
$a = my_array_keys(["hello" => 5, "goodbye" => new \Exception()]);',
|
||||
'assertions' => [
|
||||
'$a' => 'array<int, string>',
|
||||
'$a' => 'list<string>',
|
||||
],
|
||||
],
|
||||
'genericNonEmptyArrayKeys' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template T as array-key
|
||||
*
|
||||
* @param non-empty-array<T, mixed> $arr
|
||||
* @return non-empty-list<T>
|
||||
*/
|
||||
function my_array_keys($arr) {
|
||||
return array_keys($arr);
|
||||
}
|
||||
|
||||
$a = my_array_keys(["hello" => 5, "goodbye" => new \Exception()]);',
|
||||
'assertions' => [
|
||||
'$a' => 'non-empty-list<string>',
|
||||
],
|
||||
],
|
||||
'genericArrayFlip' => [
|
||||
|
Loading…
Reference in New Issue
Block a user