From 5400b5858ef1750ede656dffc894acbbbc228e88 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sun, 3 Apr 2022 11:40:43 +0200 Subject: [PATCH] Optimization? --- src/Type/Constant/ConstantArrayType.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Type/Constant/ConstantArrayType.php b/src/Type/Constant/ConstantArrayType.php index ab988b2f18..c66bb7d878 100644 --- a/src/Type/Constant/ConstantArrayType.php +++ b/src/Type/Constant/ConstantArrayType.php @@ -458,14 +458,24 @@ public function getOffsetValueType(Type $offsetType): Type { $offsetType = ArrayType::castToArrayKeyType($offsetType); $matchingValueTypes = []; + $all = true; foreach ($this->keyTypes as $i => $keyType) { if ($keyType->isSuperTypeOf($offsetType)->no()) { + $all = false; continue; } $matchingValueTypes[] = $this->valueTypes[$i]; } + if ($all) { + if (count($this->keyTypes) === 0) { + return new ErrorType(); + } + + return $this->getIterableValueType(); + } + if (count($matchingValueTypes) > 0) { $type = TypeCombinator::union(...$matchingValueTypes); if ($type instanceof ErrorType) {