Skip to content
Permalink
Browse files

Fix #2014 - prevent unusedvariable false positive when redefined in a…

…ssignment ||
  • Loading branch information...
muglug committed Aug 15, 2019
1 parent 7622f11 commit e25ce152d6cde041177f03a2af6b3edfc8a51402
@@ -941,9 +941,6 @@ public static function analyzeInstance(
return null;
}
/**
* @psalm-suppress UnusedVariable
*/
private static function taintProperty(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Expr\PropertyFetch $stmt,
@@ -306,14 +306,24 @@ function ($var_id) use ($original_vars_in_scope) {
$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 @@ public static function checkFunctionArgumentType(
return null;
}
/**
* @psalm-suppress UnusedVariable due to #2014
*/
private static function processTaintedness(
StatementsAnalyzer $statements_analyzer,
string $cased_method_id,
@@ -415,9 +415,6 @@ public static function analyze(
return null;
}
/**
* @psalm-suppress UnusedVariable
*/
private static function handleTaints(
StatementsAnalyzer $statements_analyzer,
\Psalm\Codebase $codebase,
@@ -1063,15 +1063,15 @@ function foo(object $mock) : void {
$m->setValue([get_class($mock) => "hello"]);
}'
],
'SKIPPED-defineBeforeAssignmentInConditional' => [
'defineBeforeAssignmentInConditional' => [
'<?php
$i = null;
if (rand(0, 1) || ($i = rand(0, 1))) {
echo $i;
}',
],
'SKIPPED-definedInFirstAssignmentInConditional' => [
'definedInFirstAssignmentInConditional' => [
'<?php
if (($b = rand(0, 1)) || rand(0, 1)) {
echo $b;
@@ -1768,6 +1768,15 @@ function getLastNum(array $a): int {
}',
'error_message' => 'UnusedVariable',
],
'defineInBothBranchesOfConditional' => [
'<?php
$i = null;
if (($i = rand(0, 5)) || ($i = rand(0, 3))) {
echo $i;
}',
'error_message' => 'UnusedVariable',
],
];
}
}

0 comments on commit e25ce15

Please sign in to comment.
You can’t perform that action at this time.