Skip to content
Permalink
Browse files

Fix #2560 - handle special case of array_filter on single-element array

  • Loading branch information
muglug committed Jan 11, 2020
1 parent 40406c7 commit bd846123ce47c937132dd47f13924490f78eec35
@@ -77,6 +77,18 @@ public static function getFunctionReturnType(
$statements_source->getSuppressedIssues()
);

if ($first_arg_array instanceof Type\Atomic\ObjectLike
&& $first_arg_array->is_list
&& $key_type->isSingleIntLiteral()
&& $key_type->getSingleIntLiteral()->value === 0
) {
return new Type\Union([
new Type\Atomic\TList(
$inner_type,
),
]);
}

if ($key_type->getLiteralStrings()) {
$key_type->addType(new Type\Atomic\TString);
}
@@ -2422,6 +2422,13 @@ function getCharPairs(string $line) : array {
'$array' => 'list<int>',
],
],
'specialCaseArrayFilterOnSingleEntry' => [
'<?php
/** @psalm-return list<int> */
function makeAList(int $ofThisInteger): array {
return array_filter([$ofThisInteger]);
}'
],
];
}

0 comments on commit bd84612

Please sign in to comment.
You can’t perform that action at this time.