From 006f788d6a5b7b605e35822a6dff2ff1c054b4a7 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Fri, 27 Dec 2019 16:30:42 +0300 Subject: [PATCH] Added array_fill_keys support (#2512) * Added array_fill_keys support * Removed unnecessary array_fill_keys phpdoc --- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 1 - src/Psalm/Internal/Fork/Pool.php | 1 - src/Psalm/Internal/Stubs/CoreGenericFunctions.php | 14 ++++++++++++++ tests/FunctionCallTest.php | 8 ++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 1f3bff49722..f44ab86de8c 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -1187,7 +1187,6 @@ public function setIssuesToFix(array $issues) public function setAllIssuesToFix(): void { - /** @var array $keyed_issues */ $keyed_issues = array_fill_keys(static::getSupportedIssuesToFix(), true); $this->setIssuesToFix($keyed_issues); diff --git a/src/Psalm/Internal/Fork/Pool.php b/src/Psalm/Internal/Fork/Pool.php index f0027ff8ff5..d08895dc391 100644 --- a/src/Psalm/Internal/Fork/Pool.php +++ b/src/Psalm/Internal/Fork/Pool.php @@ -287,7 +287,6 @@ private function readResultsFromChildren() // Create an array for the content received on each stream, // indexed by resource id. - /** @var array $content */ $content = array_fill_keys(array_keys($streams), ''); $terminationMessages = []; diff --git a/src/Psalm/Internal/Stubs/CoreGenericFunctions.php b/src/Psalm/Internal/Stubs/CoreGenericFunctions.php index 6586a47413c..58aa04fbd7d 100644 --- a/src/Psalm/Internal/Stubs/CoreGenericFunctions.php +++ b/src/Psalm/Internal/Stubs/CoreGenericFunctions.php @@ -217,3 +217,17 @@ function array_key_exists($key, array $search) : bool function array_merge_recursive(array $arr, array ...$arr2) { } + +/** + * @psalm-template TKey as array-key + * @psalm-template TValue + * + * @param array $keys + * @param TValue $value + * + * @return array + * @psalm-pure + */ +function array_fill_keys(array $keys, $value): array +{ +} diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index b614e577f1c..898e339fa30 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -2334,6 +2334,14 @@ function getCharPairs(string $line) : array { ); }' ], + 'arrayFillKeys' => [ + ' [ + '$result' => 'array', + ], + ], ]; }