Skip to content

Commit 5400b58

Browse files
committed
Optimization?
1 parent 91c7507 commit 5400b58

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Type/Constant/ConstantArrayType.php

+10
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,24 @@ public function getOffsetValueType(Type $offsetType): Type
458458
{
459459
$offsetType = ArrayType::castToArrayKeyType($offsetType);
460460
$matchingValueTypes = [];
461+
$all = true;
461462
foreach ($this->keyTypes as $i => $keyType) {
462463
if ($keyType->isSuperTypeOf($offsetType)->no()) {
464+
$all = false;
463465
continue;
464466
}
465467

466468
$matchingValueTypes[] = $this->valueTypes[$i];
467469
}
468470

471+
if ($all) {
472+
if (count($this->keyTypes) === 0) {
473+
return new ErrorType();
474+
}
475+
476+
return $this->getIterableValueType();
477+
}
478+
469479
if (count($matchingValueTypes) > 0) {
470480
$type = TypeCombinator::union(...$matchingValueTypes);
471481
if ($type instanceof ErrorType) {

0 commit comments

Comments
 (0)