1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #2954 - filter out used vars before checking params

This commit is contained in:
Matthew Brown 2020-03-13 20:21:49 -04:00
parent 08855c806f
commit aaf74f084a
2 changed files with 26 additions and 1 deletions

View File

@ -2240,7 +2240,7 @@ class StatementsAnalyzer extends SourceAnalyzer implements StatementsSource
*/
public function getUnusedVarLocations()
{
return $this->unused_var_locations;
return array_diff_key($this->unused_var_locations, $this->used_var_locations);
}
/**

View File

@ -1439,6 +1439,31 @@ class UnusedVariableTest extends TestCase
if ($f) {}
}'
],
'usedParamInWhileDirectly' => [
'<?php
function foo(int $index): void {
while (100 >= $index = nextNumber($index)) {
// ...
}
}
function nextNumber(int $eee): int {
return $eee + 1;
}'
],
'usedParamInWhileIndirectly' => [
'<?php
function foo(int $i): void {
$index = $i;
while (100 >= $index = nextNumber($index)) {
// ...
}
}
function nextNumber(int $i): int {
return $i + 1;
}'
],
];
}