mirror of
https://github.com/danog/psalm.git
synced 2024-11-29 20:28:59 +01:00
Fix #4958 - honour template as inheritance when comparing template types
This commit is contained in:
parent
387abc1cb6
commit
99da1daae5
@ -73,15 +73,24 @@ class ObjectComparator
|
||||
continue;
|
||||
}
|
||||
|
||||
if (\substr($intersection_container_type->defining_class, 0, 3) === 'fn-') {
|
||||
foreach ($intersection_input_types as $intersection_input_type) {
|
||||
if ($intersection_input_type instanceof TTemplateParam
|
||||
&& \substr($intersection_input_type->defining_class, 0, 3) === 'fn-'
|
||||
foreach ($intersection_input_types as $intersection_input_type) {
|
||||
if ($intersection_input_type instanceof TTemplateParam
|
||||
&& (\substr($intersection_container_type->defining_class, 0, 3) === 'fn-'
|
||||
|| \substr($intersection_input_type->defining_class, 0, 3) === 'fn-')
|
||||
) {
|
||||
if (\substr($intersection_input_type->defining_class, 0, 3) === 'fn-'
|
||||
&& \substr($intersection_container_type->defining_class, 0, 3) === 'fn-'
|
||||
&& $intersection_input_type->defining_class
|
||||
!== $intersection_container_type->defining_class
|
||||
) {
|
||||
continue 2;
|
||||
}
|
||||
|
||||
foreach ($intersection_input_type->as->getAtomicTypes() as $input_as_atomic) {
|
||||
if ($input_as_atomic->equals($intersection_container_type)) {
|
||||
continue 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1485,6 +1485,29 @@ class FunctionTemplateTest extends TestCase
|
||||
[],
|
||||
'8.0'
|
||||
],
|
||||
'templateChildClass' => [
|
||||
'<?php
|
||||
/** @template T */
|
||||
class Collection {
|
||||
/**
|
||||
* @param T $t
|
||||
*/
|
||||
private function add($t) : void {}
|
||||
|
||||
/**
|
||||
* @template TChild as T
|
||||
* @param TChild $default
|
||||
*
|
||||
* @return TChild
|
||||
*/
|
||||
public function get($default)
|
||||
{
|
||||
$this->add($default);
|
||||
|
||||
return $default;
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user