mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix #2197 - prevent false positive from try in while
This commit is contained in:
parent
7028a64440
commit
62a3598ed3
@ -414,6 +414,20 @@ class TryAnalyzer
|
||||
$statements_analyzer->registerVariableUses($locations);
|
||||
}
|
||||
}
|
||||
|
||||
$newly_unreferenced_vars = array_merge(
|
||||
$newly_unreferenced_vars,
|
||||
array_diff_key(
|
||||
$try_context->unreferenced_vars,
|
||||
$old_unreferenced_vars
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($newly_unreferenced_vars as $var_id => $locations) {
|
||||
if (!isset($context->unreferenced_vars[$var_id])) {
|
||||
$context->unreferenced_vars[$var_id] = $locations;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($stmt->finally) {
|
||||
|
@ -1171,6 +1171,29 @@ class UnusedVariableTest extends TestCase
|
||||
echo $b;
|
||||
}'
|
||||
],
|
||||
'tryWithWhile' => [
|
||||
'<?php
|
||||
function foo(): void {
|
||||
$done = false;
|
||||
|
||||
while (!$done) {
|
||||
try {
|
||||
$done = true;
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
}',
|
||||
],
|
||||
'tryWithWhileWithoutTry' => [
|
||||
'<?php
|
||||
function foo(): void {
|
||||
$done = false;
|
||||
|
||||
while (!$done) {
|
||||
$done = true;
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user