1
0
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:
Brown 2019-12-05 13:37:03 -05:00
parent 8ff33ee64d
commit 19838fc7f5
2 changed files with 17 additions and 1 deletions

View File

@ -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(),

View File

@ -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;
}
}'
],
];
}