Skip to content

Commit 504414a

Browse files
phpstan-botclaude
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 9ac8874 commit 504414a

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
@@ -2647,8 +2647,12 @@ public function assignVariable(string $variableName, Type $type, Type $nativeTyp
26472647
$scope->nativeExpressionTypes[$exprString] = new ExpressionTypeHolder($node, $nativeType, $certainty);
26482648
}
26492649

2650+
// Use $this->expressionTypes (pre-invalidation) to find intertwined entries.
2651+
// assignExpression() calls invalidateExpression() which removes entries whose
2652+
// sub-nodes contain the variable being assigned. For bidirectional reference
2653+
// links ($b = &$a), this incorrectly removes the reverse entry.
26502654
$processedIntertwinedEntries = [];
2651-
foreach ($scope->expressionTypes as $expressionType) {
2655+
foreach ($this->expressionTypes as $expressionType) {
26522656
if (!$expressionType->getExpr() instanceof IntertwinedVariableByReferenceWithExpr) {
26532657
continue;
26542658
}

0 commit comments

Comments
 (0)