diff --git a/src/Type/Constant/ConstantArrayType.php b/src/Type/Constant/ConstantArrayType.php index 7fc1b6e86ed..1a237f61794 100644 --- a/src/Type/Constant/ConstantArrayType.php +++ b/src/Type/Constant/ConstantArrayType.php @@ -540,13 +540,16 @@ public function getOffsetType(Type $offsetValueType): Type return $traverse($type); } + $offsetType = new NeverType(); foreach ($this->valueTypes as $i => $valueType) { - if ($valueType->equals($type)) { - return $this->keyTypes[$i]; + if (!$type->isSuperTypeOf($valueType)->yes()) { + continue; } + + $offsetType = TypeCombinator::union($offsetType, $this->keyTypes[$i]); } - return new ErrorType(); // undefined offset value + return $offsetType instanceof NeverType ? new ErrorType() : $offsetType; }); }