Skip to content

Commit 748bd8f

Browse files
committed
fix
1 parent ce4e3dd commit 748bd8f

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,11 +2291,13 @@ public function resolveIdentical(Expr\BinaryOp\Identical $expr, Scope $scope, Ty
22912291
}
22922292
}
22932293

2294-
if ($leftArrayType->isIterableAtLeastOnce()->yes() || $rightArrayType->isIterableAtLeastOnce()->yes()) {
2295-
$arrayTypes = $this->create($unwrappedLeftExpr->getArgs()[0]->value, new NonEmptyArrayType(), $context, $scope)->setRootExpr($expr);
2296-
return $arrayTypes->unionWith(
2297-
$this->create($unwrappedRightExpr->getArgs()[0]->value, new NonEmptyArrayType(), $context, $scope)->setRootExpr($expr),
2298-
);
2294+
if (!$rightType->isConstantScalarValue()->yes()) {
2295+
if ($leftArrayType->isIterableAtLeastOnce()->yes() || $rightArrayType->isIterableAtLeastOnce()->yes()) {
2296+
$arrayTypes = $this->create($unwrappedLeftExpr->getArgs()[0]->value, new NonEmptyArrayType(), $context, $scope)->setRootExpr($expr);
2297+
return $arrayTypes->unionWith(
2298+
$this->create($unwrappedRightExpr->getArgs()[0]->value, new NonEmptyArrayType(), $context, $scope)->setRootExpr($expr),
2299+
);
2300+
}
22992301
}
23002302
}
23012303
}

tests/PHPStan/Analyser/nsrt/list-count2.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,16 @@ function sayEqualArrayShape($arrA, array $arrB): void
9090
}
9191
assertType('list', $arrB);
9292
}
93+
94+
/**
95+
* @param list $arrA
96+
* @param array{int, int, int} $arrB
97+
*/
98+
function sayEqualArrayShapeReversed($arrA, array $arrB): void
99+
{
100+
if (count($arrA) == count($arrB)) {
101+
assertType('array{mixed, mixed, mixed}', $arrA);
102+
}
103+
assertType('list', $arrA);
104+
}
93105
}

0 commit comments

Comments
 (0)