Skip to content
Permalink
Browse files

Fix #1626 - detect dead code found in #1624

  • Loading branch information...
muglug committed May 13, 2019
1 parent abc825a commit 307cdbbbb3bfa57c5c57cfcfe232d9755f56d319
@@ -530,7 +530,9 @@ function (Clause $c) use ($mixed_var_ids) {
|| !isset($context->vars_in_scope[$var_id])
) {
$context->unreferenced_vars[$var_id] = $locations;
} elseif (isset($if_scope->possibly_assigned_var_ids[$var_id])) {
} elseif (isset($if_scope->possibly_assigned_var_ids[$var_id])
|| isset($if_context->possibly_assigned_var_ids[$var_id])
) {
if (!isset($context->unreferenced_vars[$var_id])) {
$context->unreferenced_vars[$var_id] = $locations;
} else {
@@ -2069,7 +2069,7 @@ function (FunctionLikeParameter $p) {
if ($docblock_info->template_typeofs) {
foreach ($docblock_info->template_typeofs as $template_typeof) {
foreach ($storage->params as $i => $param) {
foreach ($storage->params as $param) {
if ($param->name === $template_typeof['param_name']) {
$param_type_nullable = $param->type && $param->type->isNullable();
@@ -921,6 +921,20 @@ function foo(int $counter) : void {
}
}',
],
'useParamInsideIfLoop' => [
'<?php
function foo() : void {
$a = 1;
if (rand(0, 1)) {
while (rand(0, 1)) {
$a = 2;
}
}
echo $a;
}',
],
];
}
@@ -1438,6 +1452,61 @@ function foo() : void {
}',
'error_message' => 'UnusedVariable',
],
'detectUnusedVariableInsideIfLoop' => [
'<?php
function foo() : void {
$a = 1;
if (rand(0, 1)) {
while (rand(0, 1)) {
$a = 2;
}
}
}',
'error_message' => 'UnusedVariable',
],
'detectUnusedVariableInsideIfElseLoop' => [
'<?php
function foo() : void {
$a = 1;
if (rand(0, 1)) {
} else {
while (rand(0, 1)) {
$a = 2;
}
}
}',
'error_message' => 'UnusedVariable',
],
'detectUnusedVariableInsideIfElseifLoop' => [
'<?php
function foo() : void {
$a = 1;
if (rand(0, 1)) {
} elseif (rand(0, 1)) {
while (rand(0, 1)) {
$a = 2;
}
}
}',
'error_message' => 'UnusedVariable',
],
'detectUnusedVariableInsideIfLoopWithEchoInside' => [
'<?php
function foo() : void {
$a = 1;
if (rand(0, 1)) {
while (rand(0, 1)) {
$a = 2;
echo $a;
}
}
}',
'error_message' => 'UnusedVariable',
],
];
}
}

0 comments on commit 307cdbb

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