Skip to content

Commit b179382

Browse files
phpstan-botclaude
authored andcommitted
Fix reference type propagation for subsequent assignments
When $b = &$a creates a bidirectional reference link, assigning to either variable should propagate the type to the other for ALL subsequent assignments, not just the first one. The issue was that invalidateExpression() removed the reverse-direction intertwined entries when a variable was assigned, because the entries' sub-nodes contained the assigned variable. This fix preserves those entries by collecting them before invalidation and restoring reverse-direction entries after propagation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 98399e4 commit b179382

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/Analyser/MutatingScope.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2577,8 +2577,12 @@ public function assignVariable(string $variableName, Type $type, Type $nativeTyp
25772577
$scope->nativeExpressionTypes[$exprString] = new ExpressionTypeHolder($node, $nativeType, $certainty);
25782578
}
25792579

2580+
// Use $this->expressionTypes (pre-invalidation) to find intertwined entries.
2581+
// assignExpression() calls invalidateExpression() which removes entries whose
2582+
// sub-nodes contain the variable being assigned. For bidirectional reference
2583+
// links ($b = &$a), this incorrectly removes the reverse entry.
25802584
$processedIntertwinedEntries = [];
2581-
foreach ($scope->expressionTypes as $expressionType) {
2585+
foreach ($this->expressionTypes as $expressionType) {
25822586
if (!$expressionType->getExpr() instanceof IntertwinedVariableByReferenceWithExpr) {
25832587
continue;
25842588
}

0 commit comments

Comments
 (0)