mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #2423 - pass by ref variable status after byref assignment
This commit is contained in:
parent
8ff33ee64d
commit
19838fc7f5
@ -277,6 +277,10 @@ class AssignmentAnalyzer
|
||||
}
|
||||
|
||||
if ($array_var_id && isset($context->vars_in_scope[$array_var_id])) {
|
||||
if ($context->vars_in_scope[$array_var_id]->by_ref) {
|
||||
$assign_value_type->by_ref = true;
|
||||
}
|
||||
|
||||
// removes dependennt vars from $context
|
||||
$context->removeDescendents(
|
||||
$array_var_id,
|
||||
@ -419,7 +423,7 @@ class AssignmentAnalyzer
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($context->byref_constraints[$var_id])) {
|
||||
if (isset($context->byref_constraints[$var_id]) || $assign_value_type->by_ref) {
|
||||
$statements_analyzer->registerVariableUses([$location->getHash() => $location]);
|
||||
}
|
||||
} elseif ($assign_var instanceof PhpParser\Node\Expr\List_
|
||||
@ -1025,6 +1029,8 @@ class AssignmentAnalyzer
|
||||
return false;
|
||||
}
|
||||
|
||||
$assignment_type->by_ref = true;
|
||||
|
||||
$lhs_var_id = ExpressionAnalyzer::getVarId(
|
||||
$stmt->var,
|
||||
$statements_analyzer->getFQCLN(),
|
||||
|
@ -1317,6 +1317,16 @@ class UnusedVariableTest extends TestCase
|
||||
echo gettype($k);
|
||||
}'
|
||||
],
|
||||
'byRefVariableAfterAssignment' => [
|
||||
'<?php
|
||||
class A {
|
||||
public string $value = "";
|
||||
public function writeByRef(string $value): void {
|
||||
$update =& $this->value;
|
||||
$update = $value;
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user