mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Use appropriate template types when applying array_filter asssertions
Fixes #3008
This commit is contained in:
parent
25bd2ed5fb
commit
cae15b6c62
@ -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)
|
||||
);
|
||||
|
@ -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 {}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user