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

Prevent a templated type from hitting covariance checks

This commit is contained in:
Brown 2020-04-01 10:53:40 -04:00
parent 5876635d6d
commit fa28d767fc
2 changed files with 27 additions and 1 deletions

View File

@ -2252,7 +2252,9 @@ class TypeAnalyzer
= clone $container_param;
}
} else {
if (!($container_type_params_covariant[$i] ?? false)) {
if (!($container_type_params_covariant[$i] ?? false)
&& !$container_param->had_template
) {
// Make sure types are basically the same
if (!self::isContainedBy(
$codebase,

View File

@ -532,6 +532,30 @@ class ClassTemplateCovarianceTest extends TestCase
[],
'7.4',
],
'noNeedForCovarianceWithFunctionTemplate' => [
'<?php
class SomeParent {}
class TypeA extends SomeParent {}
class TypeB extends SomeParent {}
/** @template T of SomeParent */
class Container{
/** @var T */
public $value;
/** @param T $value */
public function __construct(SomeParent $value) {
$this->value = $value;
}
}
/**
* @template T of SomeParent
* @param Container<T> $container
*/
function run(Container $container): void{}
run(new Container(new TypeA()));'
],
];
}