Skip to content

Commit

Permalink
Added array_fill_keys support (vimeo#2512)
Browse files Browse the repository at this point in the history
* Added array_fill_keys support

* Removed unnecessary array_fill_keys phpdoc
  • Loading branch information
vudaltsov authored and muglug committed Dec 27, 2019
1 parent 6b81f8c commit 006f788
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,6 @@ public function setIssuesToFix(array $issues)

public function setAllIssuesToFix(): void
{
/** @var array<string, true> $keyed_issues */
$keyed_issues = array_fill_keys(static::getSupportedIssuesToFix(), true);

$this->setIssuesToFix($keyed_issues);
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Internal/Fork/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ private function readResultsFromChildren()

// Create an array for the content received on each stream,
// indexed by resource id.
/** @var array<int, string> $content */
$content = array_fill_keys(array_keys($streams), '');

$terminationMessages = [];
Expand Down
14 changes: 14 additions & 0 deletions src/Psalm/Internal/Stubs/CoreGenericFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<TKey> $keys
* @param TValue $value
*
* @return array<TKey, TValue>
* @psalm-pure
*/
function array_fill_keys(array $keys, $value): array
{
}
8 changes: 8 additions & 0 deletions tests/FunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,14 @@ function getCharPairs(string $line) : array {
);
}'
],
'arrayFillKeys' => [
'<?php
$keys = [1, 2, 3];
$result = array_fill_keys($keys, true);',
'assertions' => [
'$result' => 'array<int, true>',
],
],
];
}

Expand Down

0 comments on commit 006f788

Please sign in to comment.