mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Catch unused foreach key when it’s already in scope
This commit is contained in:
parent
805bfa6f2d
commit
5ddd74e7d2
@ -376,6 +376,11 @@ class ForeachChecker
|
||||
$location,
|
||||
$foreach_context->branch_point
|
||||
);
|
||||
} else {
|
||||
$statements_checker->registerVariableAssignment(
|
||||
$key_var_id,
|
||||
$location
|
||||
);
|
||||
}
|
||||
|
||||
if ($stmt->byRef && $context->collect_references) {
|
||||
|
@ -1314,6 +1314,19 @@ class UnusedVariableTest extends TestCase
|
||||
echo $a;',
|
||||
'error_message' => 'UnusedVariable',
|
||||
],
|
||||
'reusedKeyVar' => [
|
||||
'<?php
|
||||
$key = "a";
|
||||
echo $key;
|
||||
|
||||
$arr = ["foo" => "foo.foo"];
|
||||
|
||||
foreach ($arr as $key => $v) {
|
||||
list($key) = explode(".", $v);
|
||||
echo $key;
|
||||
}',
|
||||
'error_message' => 'UnusedVariable',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user