Skip to content

Commit 1eb41bd

Browse files
committed
Update TypeSpecifier.php
1 parent 2b7ace1 commit 1eb41bd

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/Analyser/TypeSpecifier.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,28 +1070,29 @@ public function specifyTypesInCondition(
10701070
} else {
10711071
$varType = $scope->getType($var->var);
10721072

1073-
if ($varType->isArray()->yes() && count($dimType->getConstantScalarTypes()) <= 1) {
1073+
$narrowedKey = AllowedArrayKeysTypes::narrowOffsetKeyType($varType, $dimType);
1074+
if ($narrowedKey !== null) {
10741075
$types = $types->unionWith(
10751076
$this->create(
1076-
$var->var,
1077-
new NonEmptyArrayType(),
1077+
$var->dim,
1078+
$narrowedKey,
10781079
$context,
10791080
$scope,
10801081
)->setRootExpr($expr),
10811082
);
10821083
}
10831084

1084-
$narrowedKey = AllowedArrayKeysTypes::narrowOffsetKeyType($varType, $dimType);
1085-
if ($narrowedKey !== null) {
1085+
if ($scope->getNativeType($var->var)->isArray()->yes()) {
10861086
$types = $types->unionWith(
10871087
$this->create(
1088-
$var->dim,
1089-
$narrowedKey,
1088+
$var->var,
1089+
new NonEmptyArrayType(),
10901090
$context,
10911091
$scope,
10921092
)->setRootExpr($expr),
10931093
);
10941094
}
1095+
10951096
}
10961097
}
10971098

0 commit comments

Comments
 (0)