Skip to content

Commit 256e8dc

Browse files
committed
Fix empty array as type in VarTagTypeRuleHelper
1 parent c534f8c commit 256e8dc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Rules/PhpDoc/VarTagTypeRuleHelper.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ private function shouldVarTagTypeBeReported(Node\Expr $expr, Type $type, Type $v
156156

157157
private function checkType(Type $type, Type $varTagType): bool
158158
{
159+
if ($type->isConstantArray()->yes()) {
160+
if ($type->isIterableAtLeastOnce()->no()) {
161+
$type = new ArrayType(new MixedType(), new MixedType());
162+
return $type->isSuperTypeOf($varTagType)->no();
163+
}
164+
}
165+
159166
if ($type->isIterable()->yes() && $varTagType->isIterable()->yes()) {
160167
if ($type->isSuperTypeOf($varTagType)->no()) {
161168
return true;

tests/PHPStan/Rules/PhpDoc/data/var-above-empty-array-widening.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@
2222

2323
/** @var int $a */
2424
$a = [];
25+
26+
$translationsTree = [];
27+
28+
/** @var array $byRef */
29+
$byRef = &$translationsTree;

0 commit comments

Comments
 (0)