Skip to content
Permalink
Browse files

Fix #2411 - allow use of covariant params in array returned value

  • Loading branch information
muglug committed Dec 4, 2019
1 parent 6ce6ad4 commit d5f5c742ceb91529c1f6735c72f3ff767422ca71
Showing with 20 additions and 0 deletions.
  1. +1 −0 src/Psalm/Type/Atomic/GenericTrait.php
  2. +19 −0 tests/Template/ClassTemplateCovarianceTest.php
@@ -309,6 +309,7 @@ public function checkGenericParams(
$source instanceof \Psalm\Internal\Analyzer\MethodAnalyzer
&& $source->getMethodName() !== '__construct'
&& empty($expected_param_covariants[$i])
&& !$this instanceof TArray
) === false) {
return false;
}
@@ -396,6 +396,25 @@ function getReference()
}
}'
],
'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;
}
}',
],
];
}

0 comments on commit d5f5c74

Please sign in to comment.
You can’t perform that action at this time.