Skip to content

Commit bbe52c7

Browse files
staabmondrejmirtes
authored andcommitted
Move TypeCombinator::intersect() out of loop
1 parent 9e0ffdd commit bbe52c7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,21 +1080,26 @@ public function getPlusType(Expr $left, Expr $right, callable $getTypeCallback):
10801080
TypeCombinator::union($leftType->getIterableValueType(), $rightType->getIterableValueType()),
10811081
);
10821082

1083+
$accessories = [];
10831084
foreach ($leftType->getConstantArrays() as $type) {
10841085
foreach ($type->getKeyTypes() as $i => $offsetType) {
10851086
if ($type->isOptionalKey($i)) {
10861087
continue;
10871088
}
10881089
$valueType = $type->getValueTypes()[$i];
1089-
$arrayType = TypeCombinator::intersect($arrayType, new HasOffsetValueType($offsetType, $valueType));
1090+
$accessories[] = new HasOffsetValueType($offsetType, $valueType);
10901091
}
10911092
}
10921093

10931094
if ($leftType->isIterableAtLeastOnce()->yes() || $rightType->isIterableAtLeastOnce()->yes()) {
1094-
$arrayType = TypeCombinator::intersect($arrayType, new NonEmptyArrayType());
1095+
$accessories[] = new NonEmptyArrayType();
10951096
}
10961097
if ($leftType->isList()->yes() && $rightType->isList()->yes()) {
1097-
$arrayType = TypeCombinator::intersect($arrayType, new AccessoryArrayListType());
1098+
$accessories[] = new AccessoryArrayListType();
1099+
}
1100+
1101+
if (count($accessories) > 0) {
1102+
$arrayType = TypeCombinator::intersect($arrayType, ...$accessories);
10981103
}
10991104

11001105
return $arrayType;

0 commit comments

Comments
 (0)