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:
parent
08855c806f
commit
aaf74f084a
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user