mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #2014 - prevent unusedvariable false positive when redefined in assignment ||
This commit is contained in:
parent
7622f11a20
commit
e25ce152d6
@ -941,9 +941,6 @@ class PropertyAssignmentAnalyzer
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-suppress UnusedVariable
|
||||
*/
|
||||
private static function taintProperty(
|
||||
StatementsAnalyzer $statements_analyzer,
|
||||
PhpParser\Node\Expr\PropertyFetch $stmt,
|
||||
|
@ -306,14 +306,24 @@ class BinaryOpAnalyzer
|
||||
|
||||
$context->assigned_var_ids = array_merge(
|
||||
$context->assigned_var_ids,
|
||||
$op_context->assigned_var_ids
|
||||
$pre_op_context->assigned_var_ids
|
||||
);
|
||||
|
||||
if ($context->collect_references) {
|
||||
$context->unreferenced_vars = array_intersect_key(
|
||||
$op_context->unreferenced_vars,
|
||||
$context->unreferenced_vars
|
||||
);
|
||||
foreach ($op_context->unreferenced_vars as $var_id => $locations) {
|
||||
if (!isset($context->unreferenced_vars[$var_id])) {
|
||||
$context->unreferenced_vars[$var_id] = $locations;
|
||||
} else {
|
||||
$new_locations = array_diff_key(
|
||||
$locations,
|
||||
$context->unreferenced_vars[$var_id]
|
||||
);
|
||||
|
||||
if ($new_locations) {
|
||||
$context->unreferenced_vars[$var_id] += $locations;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$context->vars_possibly_in_scope = array_merge(
|
||||
|
@ -2767,9 +2767,6 @@ class CallAnalyzer
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-suppress UnusedVariable due to #2014
|
||||
*/
|
||||
private static function processTaintedness(
|
||||
StatementsAnalyzer $statements_analyzer,
|
||||
string $cased_method_id,
|
||||
|
@ -415,9 +415,6 @@ class ReturnAnalyzer
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-suppress UnusedVariable
|
||||
*/
|
||||
private static function handleTaints(
|
||||
StatementsAnalyzer $statements_analyzer,
|
||||
\Psalm\Codebase $codebase,
|
||||
|
@ -1063,7 +1063,7 @@ class UnusedVariableTest extends TestCase
|
||||
$m->setValue([get_class($mock) => "hello"]);
|
||||
}'
|
||||
],
|
||||
'SKIPPED-defineBeforeAssignmentInConditional' => [
|
||||
'defineBeforeAssignmentInConditional' => [
|
||||
'<?php
|
||||
$i = null;
|
||||
|
||||
@ -1071,7 +1071,7 @@ class UnusedVariableTest extends TestCase
|
||||
echo $i;
|
||||
}',
|
||||
],
|
||||
'SKIPPED-definedInFirstAssignmentInConditional' => [
|
||||
'definedInFirstAssignmentInConditional' => [
|
||||
'<?php
|
||||
if (($b = rand(0, 1)) || rand(0, 1)) {
|
||||
echo $b;
|
||||
@ -1768,6 +1768,15 @@ class UnusedVariableTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'UnusedVariable',
|
||||
],
|
||||
'defineInBothBranchesOfConditional' => [
|
||||
'<?php
|
||||
$i = null;
|
||||
|
||||
if (($i = rand(0, 5)) || ($i = rand(0, 3))) {
|
||||
echo $i;
|
||||
}',
|
||||
'error_message' => 'UnusedVariable',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user