1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix false positive UnusedVariable

This commit is contained in:
Brown 2019-11-13 14:32:27 -05:00
parent 7516b7b0cf
commit c9e7dcfa92
2 changed files with 32 additions and 1 deletions

View File

@ -308,6 +308,16 @@ class TernaryAnalyzer
$t_else_context->unreferenced_vars
);
foreach ($context->unreferenced_vars as $var_id => $locations) {
if (isset($t_else_context->unreferenced_vars[$var_id])) {
$context->unreferenced_vars[$var_id] += $t_else_context->unreferenced_vars[$var_id];
}
if (isset($t_if_context->unreferenced_vars[$var_id])) {
$context->unreferenced_vars[$var_id] += $t_if_context->unreferenced_vars[$var_id];
}
}
$lhs_type = null;
if ($stmt->if) {

View File

@ -1270,7 +1270,28 @@ class UnusedVariableTest extends TestCase
$arr["a"]["b"][$c] = 1;
return $arr;
}',
]
],
'binaryOpIncrementInElse' => [
'<?php
function foo(int $i, string $alias) : void {
echo $alias ?: $i++;
echo $i;
}'
],
'binaryOpIncrementInCond' => [
'<?php
function foo(int $i, string $alias) : void {
echo $i++ ?: $alias;
echo $i;
}'
],
'binaryOpIncrementInIf' => [
'<?php
function foo(int $i, string $alias) : void {
echo rand(0, 1) ? $i++ : $alias;
echo $i;
}'
],
];
}