1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #4326 - prevent more mapping than necessary

This commit is contained in:
Matt Brown 2020-10-14 21:22:51 -04:00
parent d8d17a6587
commit 4539a2f27e
2 changed files with 47 additions and 1 deletions

View File

@ -876,6 +876,10 @@ class UnionTemplateHandler
string $defining_class,
array $visited_classes = []
) : ?array {
if (isset($visited_classes[$defining_class])) {
return null;
}
if (isset($template_types[$param_name][$defining_class])) {
$mapped_type = $template_types[$param_name][$defining_class][0];
@ -883,7 +887,6 @@ class UnionTemplateHandler
if (count($mapped_type_atomic_types) > 1
|| !$mapped_type_atomic_types[0] instanceof Atomic\TTemplateParam
|| isset($visited_classes[$defining_class])
) {
return $template_types[$param_name][$defining_class];
}

View File

@ -3005,6 +3005,49 @@ class ClassTemplateTest extends TestCase
}
}'
],
'flippedParamsInside' => [
'<?php
/**
* @template A
* @template B
*/
abstract class Foo
{
/** @return Traversable<A, B> */
public abstract function getTraversable() : Traversable;
/**
* @param Foo<B, A> $flipped
* @return Traversable<B, A>
*/
public function getFlippedTraversable(Foo $flipped): Traversable
{
return $flipped->getTraversable();
}
}'
],
'flippedParamsOutside' => [
'<?php
/**
* @template B
* @template A
* @param Foo<B, A> $flipped
* @return Traversable<B, A>
*/
function getFlippedTraversable(Foo $flipped): Traversable {
return $flipped->getTraversable();
}
/**
* @template A
* @template B
*/
abstract class Foo
{
/** @return Traversable<A, B> */
public abstract function getTraversable() : Traversable;
}'
],
];
}