1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #4958 - honour template as inheritance when comparing template types

This commit is contained in:
Matt Brown 2021-01-09 18:58:29 -05:00 committed by Daniil Gentili
parent 387abc1cb6
commit 99da1daae5
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 36 additions and 4 deletions

View File

@ -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;
}
}
}
}

View File

@ -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;
}
}'
],
];
}