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

Only extend covariant flag to vars without template param

This commit is contained in:
Brown 2019-11-04 11:12:59 -05:00
parent 4f9cf54005
commit 4bf632bc23
3 changed files with 16 additions and 4 deletions

View File

@ -488,7 +488,10 @@ class Populator
$storage->template_type_extends[$parent_storage->name][$mapped_name] = $type;
}
if (is_int($i) && ($parent_storage->template_covariants[$i] ?? false)) {
if (is_int($i)
&& ($parent_storage->template_covariants[$i] ?? false)
&& !$type->hasTemplate()
) {
$storage->template_covariants[$i] = true;
}
}
@ -623,7 +626,10 @@ class Populator
$storage->template_type_extends[$parent_interface_storage->name][$mapped_name] = $type;
}
if (is_int($i) && ($parent_interface_storage->template_covariants[$i] ?? false)) {
if (is_int($i)
&& ($parent_interface_storage->template_covariants[$i] ?? false)
&& !$type->hasTemplate()
) {
$storage->template_covariants[$i] = true;
}
}
@ -719,7 +725,10 @@ class Populator
$storage->template_type_extends[$implemented_interface_storage->name][$mapped_name] = $type;
}
if (is_int($i) && ($implemented_interface_storage->template_covariants[$i] ?? false)) {
if (is_int($i)
&& ($implemented_interface_storage->template_covariants[$i] ?? false)
&& !$type->hasTemplate()
) {
$storage->template_covariants[$i] = true;
}
}

View File

@ -49,6 +49,10 @@ class UnionTemplateHandler
}
if ($replace) {
if (array_values($original_atomic_types) === $atomic_types) {
return $union_type;
}
if (!$atomic_types) {
throw new \UnexpectedValueException('Cannot remove all keys');
}

View File

@ -1637,7 +1637,6 @@ class ClassTemplateExtendsTest extends TestCase
/**
* @psalm-suppress MissingTemplateParam
* @psalm-suppress InvalidTemplateParam
*
* @psalm-param array<T> $elements
* @psalm-return ArrayCollection<T>