mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 13:51:54 +01:00
Fix #4326 - prevent more mapping than necessary
This commit is contained in:
parent
84126fbbca
commit
1915f34959
@ -876,6 +876,10 @@ class UnionTemplateHandler
|
|||||||
string $defining_class,
|
string $defining_class,
|
||||||
array $visited_classes = []
|
array $visited_classes = []
|
||||||
) : ?array {
|
) : ?array {
|
||||||
|
if (isset($visited_classes[$defining_class])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($template_types[$param_name][$defining_class])) {
|
if (isset($template_types[$param_name][$defining_class])) {
|
||||||
$mapped_type = $template_types[$param_name][$defining_class][0];
|
$mapped_type = $template_types[$param_name][$defining_class][0];
|
||||||
|
|
||||||
@ -883,7 +887,6 @@ class UnionTemplateHandler
|
|||||||
|
|
||||||
if (count($mapped_type_atomic_types) > 1
|
if (count($mapped_type_atomic_types) > 1
|
||||||
|| !$mapped_type_atomic_types[0] instanceof Atomic\TTemplateParam
|
|| !$mapped_type_atomic_types[0] instanceof Atomic\TTemplateParam
|
||||||
|| isset($visited_classes[$defining_class])
|
|
||||||
) {
|
) {
|
||||||
return $template_types[$param_name][$defining_class];
|
return $template_types[$param_name][$defining_class];
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user