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:
parent
a8ed6ba9c4
commit
3e98c800ec
@ -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')
|
||||
|
@ -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";
|
||||
}
|
||||
);
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user