1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #2309 - prevent closure-inferred generic template params overwriting parent ones

This commit is contained in:
Brown 2019-11-06 13:13:02 -05:00
parent a8ed6ba9c4
commit 3e98c800ec
2 changed files with 32 additions and 2 deletions

View File

@ -484,8 +484,6 @@ class CallAnalyzer
$codebase
);
$template_result->generic_params = $replace_template_result->generic_params;
$closure_id = strtolower($statements_analyzer->getFilePath())
. ':' . $arg->value->getLine()
. ':' . (int)$arg->value->getAttribute('startFilePos')

View File

@ -1966,6 +1966,38 @@ class ClassTemplateTest extends TestCase
}
}'
],
'useMethodWithExistingGenericParam' => [
'<?php
class Bar {
public function getFoo(): string {
return "foo";
}
}
/**
* @template TKey
* @template T
*/
interface Collection {
/**
* @param Closure(T=):bool $p
* @return Collection<TKey, T>
*/
public function filter(Closure $p);
}
/**
* @param Collection<int, Bar> $c
* @psalm-return Collection<int, Bar>
*/
function filter(Collection $c, string $name) {
return $c->filter(
function (Bar $f) use ($name) {
return $f->getFoo() === "foo";
}
);
}'
],
];
}