Skip to content

Commit fd723ba

Browse files
committed
Skip deep expression when root expression changes while scope generalization
1 parent c87456e commit fd723ba

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Analyser/MutatingScope.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5296,14 +5296,35 @@ private function generalizeVariableTypeHolders(
52965296
array $otherVariableTypeHolders,
52975297
): array
52985298
{
5299+
$sortByExprStringLength = static function (string $exprA, string $exprB): int {
5300+
return strlen($exprA) <=> strlen($exprB);
5301+
};
5302+
5303+
uksort($variableTypeHolders, $sortByExprStringLength);
5304+
uksort($otherVariableTypeHolders, $sortByExprStringLength);
5305+
5306+
$changedArrays = [];
52995307
foreach ($variableTypeHolders as $variableExprString => $variableTypeHolder) {
53005308
if (!isset($otherVariableTypeHolders[$variableExprString])) {
53015309
continue;
53025310
}
53035311

5312+
foreach($changedArrays as $changedExpr) {
5313+
if (str_starts_with($variableExprString, $changedExpr)) {
5314+
continue 2;
5315+
}
5316+
}
5317+
5318+
$generalizedType = $this->generalizeType($variableTypeHolder->getType(), $otherVariableTypeHolders[$variableExprString]->getType(), 0);
5319+
if (
5320+
$generalizedType->isArray()->yes() &&
5321+
!$generalizedType->equals($variableTypeHolder->getType()))
5322+
{
5323+
$changedArrays[] = $variableExprString;
5324+
}
53045325
$variableTypeHolders[$variableExprString] = new ExpressionTypeHolder(
53055326
$variableTypeHolder->getExpr(),
5306-
$this->generalizeType($variableTypeHolder->getType(), $otherVariableTypeHolders[$variableExprString]->getType(), 0),
5327+
$generalizedType,
53075328
$variableTypeHolder->getCertainty(),
53085329
);
53095330
}

0 commit comments

Comments
 (0)