Skip to content

Commit

Permalink
fix covariant type check when template has bound
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach authored and ondrejmirtes committed Jul 8, 2020
1 parent 87e3764 commit b9c29a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Type/Generic/TemplateObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function toArgument(): TemplateType
return new self(
$this->scope,
new TemplateTypeArgumentStrategy(),
TemplateTypeVariance::createInvariant(),
$this->variance,
$this->name,
$this->getClassName()
);
Expand Down
16 changes: 10 additions & 6 deletions tests/PHPStan/Rules/Generics/MethodSignatureVarianceRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,31 @@ public function testRule(): void
$this->analyse([__DIR__ . '/data/method-signature-variance.php'], [
[
'Template type T is declared as covariant, but occurs in contravariant position in parameter a of method MethodSignatureVariance\C::a().',
23,
25,
],
[
'Template type T is declared as covariant, but occurs in invariant position in parameter b of method MethodSignatureVariance\C::a().',
23,
25,
],
[
'Template type T is declared as covariant, but occurs in contravariant position in parameter c of method MethodSignatureVariance\C::a().',
23,
25,
],
[
'Template type W is declared as covariant, but occurs in contravariant position in parameter d of method MethodSignatureVariance\C::a().',
25,
],
[
'Template type U is declared as covariant, but occurs in contravariant position in parameter a of method MethodSignatureVariance\C::b().',
33,
35,
],
[
'Template type U is declared as covariant, but occurs in invariant position in parameter b of method MethodSignatureVariance\C::b().',
33,
35,
],
[
'Template type U is declared as covariant, but occurs in contravariant position in parameter c of method MethodSignatureVariance\C::b().',
33,
35,
],
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ interface Invariant {

/**
* @template-covariant T
* @template-covariant W of \DateTimeInterface
*/
class C {
/**
* @param Out<T> $a
* @param Invariant<T> $b
* @param T $c
* @param W $d
* @return T
*/
function a($a, $b, $c) {
function a($a, $b, $c, $d) {
return $c;
}
/**
Expand Down

0 comments on commit b9c29a5

Please sign in to comment.