Skip to content
Permalink
Browse files

Fix #2197 - prevent false positive from try in while

  • Loading branch information
muglug committed Nov 9, 2019
1 parent 7028a64 commit 62a3598ed3f78a156c5f13dd27fcb3eabb152938
Showing with 37 additions and 0 deletions.
  1. +14 −0 src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php
  2. +23 −0 tests/UnusedVariableTest.php
@@ -414,6 +414,20 @@ function ($fq_catch_class) use ($codebase) {
$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 @@ function b(): void {
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;
}
}',
],
];
}

0 comments on commit 62a3598

Please sign in to comment.
You can’t perform that action at this time.