mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #2411 - allow use of covariant params in array returned value
This commit is contained in:
parent
6ce6ad4483
commit
d5f5c742ce
@ -309,6 +309,7 @@ trait GenericTrait
|
||||
$source instanceof \Psalm\Internal\Analyzer\MethodAnalyzer
|
||||
&& $source->getMethodName() !== '__construct'
|
||||
&& empty($expected_param_covariants[$i])
|
||||
&& !$this instanceof TArray
|
||||
) === false) {
|
||||
return false;
|
||||
}
|
||||
|
@ -396,6 +396,25 @@ class ClassTemplateCovarianceTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'allowCovariantReturnOnArrays' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template-covariant T
|
||||
*/
|
||||
class A {
|
||||
private $arr;
|
||||
|
||||
/** @psalm-param array<mixed, T> $arr */
|
||||
public function __construct(array $arr) {
|
||||
$this->arr = $arr;
|
||||
}
|
||||
|
||||
/** @psalm-return array<mixed, T> */
|
||||
public function foo(): array {
|
||||
return $this->arr;
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user