Skip to content

Commit 95d749e

Browse files
committed
Update TypeSpecifier.php
1 parent 3b43170 commit 95d749e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,16 @@ private function narrowUnionByArraySize(FuncCall $countFuncCall, UnionType $argT
970970
if ($isSize->no()) {
971971
continue;
972972
}
973+
974+
if ($sizeType instanceof ConstantIntegerType && $innerType->isList()->yes()) {
975+
// turn optional offsets non-optional
976+
$valueTypesBuilder = ConstantArrayTypeBuilder::createEmpty();
977+
for ($i = 0; $i < $sizeType->getValue(); $i++) {
978+
$offsetType = new ConstantIntegerType($i);
979+
$valueTypesBuilder->setOffsetValueType($offsetType, $innerType->getOffsetValueType($offsetType));
980+
}
981+
$innerType = $valueTypesBuilder->getArray();
982+
}
973983
}
974984
if ($context->falsey()) {
975985
if (!$isSize->yes()) {
@@ -1059,6 +1069,7 @@ private function specifyTypesForConstantBinaryExpression(
10591069

10601070
$funcTypes = $this->create($exprNode, $constantType, $context, false, $scope, $rootExpr);
10611071
if ($isNormalCount->yes() && $argType->isList()->yes() && $context->truthy() && $constantType->getValue() < ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT) {
1072+
// turn optional offsets non-optional
10621073
$valueTypesBuilder = ConstantArrayTypeBuilder::createEmpty();
10631074
for ($i = 0; $i < $constantType->getValue(); $i++) {
10641075
$offsetType = new ConstantIntegerType($i);

0 commit comments

Comments
 (0)