diff --git a/src/Psalm/Internal/Stubs/CoreGenericFunctions.phpstub b/src/Psalm/Internal/Stubs/CoreGenericFunctions.phpstub index 311156741..a8024e541 100644 --- a/src/Psalm/Internal/Stubs/CoreGenericFunctions.phpstub +++ b/src/Psalm/Internal/Stubs/CoreGenericFunctions.phpstub @@ -1,12 +1,13 @@ |array * - * @param array $arr - * @param mixed $search_value - * @param bool $strict + * @param A $arr + * @param mixed $search_value + * @param bool $strict * - * @return list + * @return (A is non-empty-array ? non-empty-list : list) * @psalm-pure */ function array_keys(array $arr, $search_value = null, bool $strict = false) diff --git a/tests/Template/FunctionTemplateTest.php b/tests/Template/FunctionTemplateTest.php index e44a12af7..faa5e09a7 100644 --- a/tests/Template/FunctionTemplateTest.php +++ b/tests/Template/FunctionTemplateTest.php @@ -93,7 +93,7 @@ class FunctionTemplateTest extends TestCase * @template T as array-key * * @param array $arr - * @return array + * @return list */ 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', + '$a' => 'list', + ], + ], + 'genericNonEmptyArrayKeys' => [ + ' $arr + * @return non-empty-list + */ + function my_array_keys($arr) { + return array_keys($arr); + } + + $a = my_array_keys(["hello" => 5, "goodbye" => new \Exception()]);', + 'assertions' => [ + '$a' => 'non-empty-list', ], ], 'genericArrayFlip' => [