1
0
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:
Brown 2019-12-04 10:49:07 -05:00
parent 6ce6ad4483
commit d5f5c742ce
2 changed files with 20 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;
}
}',
],
];
}