diff --git a/src/Rules/PhpDoc/VarTagTypeRuleHelper.php b/src/Rules/PhpDoc/VarTagTypeRuleHelper.php index a2916518aa..f6656d6683 100644 --- a/src/Rules/PhpDoc/VarTagTypeRuleHelper.php +++ b/src/Rules/PhpDoc/VarTagTypeRuleHelper.php @@ -171,6 +171,10 @@ private function checkType(Type $type, Type $varTagType): bool return $this->checkType($innerType, $innerVarTagType); } + if ($type->isConstantValue()->yes()) { + return $type->isSuperTypeOf($varTagType)->no(); + } + return !$type->isSuperTypeOf($varTagType)->yes(); } diff --git a/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php b/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php index 4b860751e7..959a87c847 100644 --- a/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php @@ -356,10 +356,6 @@ public function testEmptyArrayInitWithWiderPhpDoc(bool $checkTypeAgainstNativeTy $errors = !$checkTypeAgainstNativeType ? [] : [ - [ - 'PHPDoc tag @var with type int|null is not subtype of native type null.', - 6, - ], [ 'PHPDoc tag @var with type int is not subtype of native type array{}.', 24,