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:
parent
7516b7b0cf
commit
c9e7dcfa92
@ -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) {
|
||||
|
@ -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;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user