Skip to content

Commit 1961e2d

Browse files
committed
fix
1 parent 9fac9a6 commit 1961e2d

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
@@ -936,18 +936,6 @@ public function specifyTypesInCondition(
936936
&& !$scope->getType($var->var) instanceof MixedType
937937
) {
938938
$dimType = $scope->getType($var->dim);
939-
$varType = $scope->getType($var->var);
940-
941-
if ($varType->isArray()->yes()) {
942-
$types = $types->unionWith(
943-
$this->create(
944-
$var->var,
945-
new NonEmptyArrayType(),
946-
$context,
947-
$scope,
948-
)->setRootExpr($expr),
949-
);
950-
}
951939

952940
if ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType) {
953941
$types = $types->unionWith(
@@ -960,6 +948,18 @@ public function specifyTypesInCondition(
960948
);
961949
} else {
962950
$varType = $scope->getType($var->var);
951+
952+
if ($varType->isArray()->yes() && $dimType->isConstantScalarValue()->no()) {
953+
$types = $types->unionWith(
954+
$this->create(
955+
$var->var,
956+
new NonEmptyArrayType(),
957+
$context,
958+
$scope,
959+
)->setRootExpr($expr),
960+
);
961+
}
962+
963963
$narrowedKey = AllowedArrayKeysTypes::narrowOffsetKeyType($varType, $dimType);
964964
if ($narrowedKey !== null) {
965965
$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)