Skip to content

Commit e3a0838

Browse files
Add test
1 parent c72d0f3 commit e3a0838

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,14 +601,23 @@ public function testGenericSubtypeWithStrictCheck(): void
601601
131,
602602
'Template type E on class GenericSubtype\IRepository is not covariant. Learn more: <fg=cyan>https://phpstan.org/blog/whats-up-with-template-covariant</>',
603603
],
604+
[
605+
'PHPDoc tag @var with type GenericSubtype\Collection<int> is not subtype of type GenericSubtype\Collection<string>.',
606+
162,
607+
],
604608
]);
605609
}
606610

607611
public function testGenericSubtypeWithoutStrictCheck(): void
608612
{
609613
$this->checkTypeAgainstPhpDocType = true;
610614
$this->strictWideningCheck = false;
611-
$this->analyse([__DIR__ . '/data/generic-subtype.php'], []);
615+
$this->analyse([__DIR__ . '/data/generic-subtype.php'], [
616+
[
617+
'PHPDoc tag @var with type GenericSubtype\Collection<int> is not subtype of type GenericSubtype\Collection<string>.',
618+
162,
619+
],
620+
]);
612621
}
613622

614623
public function testNewIsAlwaysFinalClass(): void

tests/PHPStan/Rules/PhpDoc/data/generic-subtype.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,19 @@ protected function getTargetRepository(): IRepository
146146
*/
147147
protected function test($repository): void {}
148148
}
149+
150+
/** @template T */
151+
class Collection
152+
{
153+
}
154+
155+
abstract class AlwaysFail
156+
{
157+
/** @return Collection<string> */
158+
abstract public function getCollection(): Collection;
159+
160+
public function test(): void {
161+
/** @var Collection<int> $collection */
162+
$collection = $this->getCollection();
163+
}
164+
}

0 commit comments

Comments
 (0)