Skip to content

Commit e345897

Browse files
committed
fix
1 parent 3b9b6ba commit e345897

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -917,18 +917,6 @@ public function specifyTypesInCondition(
917917
&& !$scope->getType($var->var) instanceof MixedType
918918
) {
919919
$dimType = $scope->getType($var->dim);
920-
$varType = $scope->getType($var->var);
921-
922-
if ($varType->isArray()->yes()) {
923-
$types = $types->unionWith(
924-
$this->create(
925-
$var->var,
926-
new NonEmptyArrayType(),
927-
$context,
928-
$scope,
929-
)->setRootExpr($expr),
930-
);
931-
}
932920

933921
if ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType) {
934922
$types = $types->unionWith(
@@ -941,6 +929,18 @@ public function specifyTypesInCondition(
941929
);
942930
} else {
943931
$varType = $scope->getType($var->var);
932+
933+
if ($varType->isArray()->yes() && $dimType->isConstantScalarValue()->no()) {
934+
$types = $types->unionWith(
935+
$this->create(
936+
$var->var,
937+
new NonEmptyArrayType(),
938+
$context,
939+
$scope,
940+
)->setRootExpr($expr),
941+
);
942+
}
943+
944944
$narrowedKey = AllowedArrayKeysTypes::narrowOffsetKeyType($varType, $dimType);
945945
if ($narrowedKey !== null) {
946946
$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
@@ -285,7 +285,7 @@ public function testBug7190(): void
285285
{
286286
$this->analyse([__DIR__ . '/../Properties/data/bug-7190.php'], [
287287
[
288-
'Offset int on array<int, int> on left side of ?? always exists and is not nullable.',
288+
'Offset int on non-empty-array<int, int> on left side of ?? always exists and is not nullable.',
289289
20,
290290
],
291291
]);

0 commit comments

Comments
 (0)