Skip to content

Commit

Permalink
Use appropriate template types when applying array_filter asssertions
Browse files Browse the repository at this point in the history
Fixes #3008
  • Loading branch information
muglug committed Mar 24, 2020
1 parent 25bd2ed commit cae15b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Expand Up @@ -203,7 +203,7 @@ function (\Psalm\Storage\FunctionLikeParameter $param) {
$changed_var_ids,
['$inner_type' => true],
$statements_source,
[],
$statements_source->getTemplateTypeMap(),
false,
new CodeLocation($statements_source, $stmt)
);
Expand Down
20 changes: 20 additions & 0 deletions tests/Template/FunctionClassStringTemplateTest.php
Expand Up @@ -649,6 +649,26 @@ function bar(string $e, string $expected) : void {
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 {}'
],
];
}

Expand Down

0 comments on commit cae15b6

Please sign in to comment.