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:
parent
5876635d6d
commit
fa28d767fc
@ -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,
|
||||
|
@ -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()));'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user