1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Use appropriate template types when applying array_filter asssertions

Fixes #3008
This commit is contained in:
Brown 2020-03-24 12:15:56 -04:00
parent 25bd2ed5fb
commit cae15b6c62
2 changed files with 21 additions and 1 deletions

View File

@ -203,7 +203,7 @@ class ArrayFilterReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionReturn
$changed_var_ids,
['$inner_type' => true],
$statements_source,
[],
$statements_source->getTemplateTypeMap(),
false,
new CodeLocation($statements_source, $stmt)
);

View File

@ -649,6 +649,26 @@ class FunctionClassStringTemplateTest extends TestCase
if ($e !== $expected) {}
}',
],
'refineByArrayFilterIntersection' => [
'<?php
/**
* @template T
* @param array<Bar> $bars
* @psalm-param class-string<T> $class
* @return array<T&Bar>
*/
function getBarsThatAreInstancesOf(array $bars, string $class): array
{
return \array_filter(
$bars,
function (Bar $bar) use ($class): bool {
return $bar instanceof $class;
}
);
}
interface Bar {}'
],
];
}