diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index 7453ae3315..88a7617901 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -268,8 +268,12 @@ public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType public function hasOffsetValueType(Type $offsetType): TrinaryLogic { - $allowedArrayKeys = AllowedArrayKeysTypes::getType(); - $offsetType = TypeCombinator::intersect($allowedArrayKeys, $offsetType)->toArrayKey(); + $offsetArrayKeyType = $offsetType->toArrayKey(); + if ($offsetArrayKeyType instanceof ErrorType) { + $allowedArrayKeys = AllowedArrayKeysTypes::getType(); + $offsetArrayKeyType = TypeCombinator::intersect($allowedArrayKeys, $offsetType)->toArrayKey(); + } + $offsetType = $offsetArrayKeyType; if ($this->getKeyType()->isSuperTypeOf($offsetType)->no() && ($offsetType->isString()->no() || !$offsetType->isConstantScalarValue()->no()) diff --git a/src/Type/Constant/ConstantArrayType.php b/src/Type/Constant/ConstantArrayType.php index 9418c81fa7..b4e2ed6f36 100644 --- a/src/Type/Constant/ConstantArrayType.php +++ b/src/Type/Constant/ConstantArrayType.php @@ -582,8 +582,11 @@ public function findTypeAndMethodNames(): array public function hasOffsetValueType(Type $offsetType): TrinaryLogic { - $allowedArrayKeys = AllowedArrayKeysTypes::getType(); - $offsetArrayKeyType = TypeCombinator::intersect($allowedArrayKeys, $offsetType)->toArrayKey(); + $offsetArrayKeyType = $offsetType->toArrayKey(); + if ($offsetArrayKeyType instanceof ErrorType) { + $allowedArrayKeys = AllowedArrayKeysTypes::getType(); + $offsetArrayKeyType = TypeCombinator::intersect($allowedArrayKeys, $offsetType)->toArrayKey(); + } return $this->recursiveHasOffsetValueType($offsetArrayKeyType); }