Skip to content

Commit 9368a99

Browse files
committed
fix
1 parent 19a84a4 commit 9368a99

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/Analyser/TypeSpecifier.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,18 +1065,6 @@ public function specifyTypesInCondition(
10651065
&& !$scope->getType($var->var) instanceof MixedType
10661066
) {
10671067
$dimType = $scope->getType($var->dim);
1068-
$varType = $scope->getType($var->var);
1069-
1070-
if ($varType->isArray()->yes()) {
1071-
$types = $types->unionWith(
1072-
$this->create(
1073-
$var->var,
1074-
new NonEmptyArrayType(),
1075-
$context,
1076-
$scope,
1077-
)->setRootExpr($expr),
1078-
);
1079-
}
10801068

10811069
if ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType) {
10821070
$types = $types->unionWith(
@@ -1089,6 +1077,18 @@ public function specifyTypesInCondition(
10891077
);
10901078
} else {
10911079
$varType = $scope->getType($var->var);
1080+
1081+
if ($varType->isArray()->yes() && $dimType->isConstantScalarValue()->no()) {
1082+
$types = $types->unionWith(
1083+
$this->create(
1084+
$var->var,
1085+
new NonEmptyArrayType(),
1086+
$context,
1087+
$scope,
1088+
)->setRootExpr($expr),
1089+
);
1090+
}
1091+
10921092
$narrowedKey = AllowedArrayKeysTypes::narrowOffsetKeyType($varType, $dimType);
10931093
if ($narrowedKey !== null) {
10941094
$types = $types->unionWith(

tests/PHPStan/Analyser/nsrt/bug-7000.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function doBar(): void
1212
$composer = array();
1313
foreach (array('require', 'require-dev') as $linkType) {
1414
if (isset($composer[$linkType])) {
15-
assertType('non-empty-array{require?: array<string, string>, require-dev?: array<string, string>}', $composer);
15+
assertType('array{require?: array<string, string>, require-dev?: array<string, string>}', $composer);
1616
foreach ($composer[$linkType] as $x) {}
1717
}
1818
}

tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function testBug7190(): void
280280
{
281281
$this->analyse([__DIR__ . '/../Properties/data/bug-7190.php'], [
282282
[
283-
'Offset int on array<int, int> on left side of ?? always exists and is not nullable.',
283+
'Offset int on non-empty-array<int, int> on left side of ?? always exists and is not nullable.',
284284
20,
285285
],
286286
]);

0 commit comments

Comments
 (0)