Skip to content

Commit c742c79

Browse files
committed
Restructure conditionals, fix min/max limit calculation
1 parent b293f1f commit c742c79

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,9 +1103,14 @@ private function specifyTypesForCountFuncCall(
11031103
$sizeType instanceof IntegerRangeType
11041104
&& $sizeType->getMin() !== null
11051105
&& $sizeType->getMin() <= ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT
1106-
&& ($sizeType->getMax() === null || $sizeType->getMax() - $sizeType->getMin() <= ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT)
11071106
&& $arrayType->getKeyType()->isSuperTypeOf(IntegerRangeType::fromInterval(0, $sizeType->getMin() - 1))->yes()
1108-
&& ($sizeType->getMax() === null || $arrayType->getKeyType()->isSuperTypeOf(IntegerRangeType::fromInterval(0, $sizeType->getMax() - 1))->yes())
1107+
&& (
1108+
$sizeType->getMax() === null
1109+
|| (
1110+
$sizeType->getMax() <= ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT
1111+
&& $arrayType->getKeyType()->isSuperTypeOf(IntegerRangeType::fromInterval(0, $sizeType->getMax() - 1))->yes()
1112+
)
1113+
)
11091114
) {
11101115
// turn optional offsets non-optional
11111116
$valueTypesBuilder = ConstantArrayTypeBuilder::createEmpty();

0 commit comments

Comments
 (0)