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

Fix #4901 - simplify mapping of template types within class

This commit is contained in:
Matthew Brown 2020-12-29 12:24:33 +00:00
parent ab5ddb1514
commit ddd99970a9
2 changed files with 27 additions and 6 deletions

View File

@ -91,15 +91,13 @@ class ClassTemplateParamCollector
$e = $static_class_storage->template_extended_params;
if ($lhs_type_part instanceof TGenericObject) {
if ($class_storage === $static_class_storage && $static_class_storage->template_types) {
if ($class_storage === $static_class_storage && $class_storage->template_types) {
$i = 0;
foreach ($static_class_storage->template_types as $type_name => $_) {
foreach ($class_storage->template_types as $type_name => $_) {
if (isset($lhs_type_part->type_params[$i])) {
if (!$self_call || $static_fq_class_name !== $static_class_storage->name) {
$class_template_params[$type_name][$static_class_storage->name]
= $lhs_type_part->type_params[$i];
}
$class_template_params[$type_name][$class_storage->name]
= $lhs_type_part->type_params[$i];
}
$i++;

View File

@ -3255,6 +3255,29 @@ class ClassTemplateTest extends TestCase
return new Foo(Foo::A);
}'
],
'callTemplatedMethodOnSameClass' => [
'<?php
/**
* @template T as object
*/
class Mapper {
/**
* @param T $e
* @return T
*/
public function foo($e) {
return $e;
}
/**
* @param T $e
* @return T
*/
public function passthru($e) {
return $this->foo($e);
}
}'
],
];
}