Skip to content

Commit 3adc625

Browse files
committed
Get rid of instanceof ErrorType
1 parent 09a7355 commit 3adc625

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@
173173
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
174174
use PHPStan\Type\Constant\ConstantIntegerType;
175175
use PHPStan\Type\Constant\ConstantStringType;
176-
use PHPStan\Type\ErrorType;
177176
use PHPStan\Type\FileTypeMapper;
178177
use PHPStan\Type\GeneralizePrecision;
179178
use PHPStan\Type\Generic\TemplateTypeHelper;
@@ -6157,12 +6156,17 @@ private function produceArrayDimFetchAssignValueToWrite(array $dimFetchStack, ar
61576156
$offsetValueType = new ConstantArrayType([], []);
61586157

61596158
} else {
6160-
$add = $offsetValueType->hasOffsetValueType($offsetType)->maybe();
6161-
$offsetValueType = $offsetValueType->getOffsetValueType($offsetType);
6162-
if ($offsetValueType instanceof ErrorType) {
6159+
$has = $offsetValueType->hasOffsetValueType($offsetType);
6160+
if ($has->yes()) {
6161+
$offsetValueType = $offsetValueType->getOffsetValueType($offsetType);
6162+
} elseif ($has->maybe()) {
6163+
if (!$scope->hasExpressionType($dimFetch)->yes()) {
6164+
$offsetValueType = TypeCombinator::union($offsetValueType->getOffsetValueType($offsetType), new ConstantArrayType([], []));
6165+
} else {
6166+
$offsetValueType = $offsetValueType->getOffsetValueType($offsetType);
6167+
}
6168+
} else {
61636169
$offsetValueType = new ConstantArrayType([], []);
6164-
} elseif ($add && !$scope->hasExpressionType($dimFetch)->yes()) {
6165-
$offsetValueType = TypeCombinator::union($offsetValueType, new ConstantArrayType([], []));
61666170
}
61676171
}
61686172

0 commit comments

Comments
 (0)