Skip to content
Permalink
Browse files

Add better handling of catch-reassigned vars

Ref #2052
  • Loading branch information...
muglug committed Aug 26, 2019
1 parent f4f4a32 commit febd60dade5fa4e55daaf5257a870654d77b9b2d
Showing with 16 additions and 0 deletions.
  1. +2 −0 src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php
  2. +14 −0 tests/UnusedVariableTest.php
@@ -362,6 +362,8 @@ function ($fq_catch_class) use ($codebase) {
&& $old_unreferenced_vars[$var_id] !== $locations
) {
$statements_analyzer->registerVariableUses($locations);
} elseif (isset($newly_unreferenced_vars[$var_id])) {
$context->unreferenced_vars[$var_id] = $newly_unreferenced_vars[$var_id];
}
}
}
@@ -1088,6 +1088,20 @@ function foo(A $a) : void {
$a->bar($i);
}',
],
'noUnusedVariableAfterRedeclaredInCatch' => [
'<?php
$path = "";
echo $path;
try {
// do nothing
} catch (\Exception $exception) {
$path = "hello";
}
echo $path;'
],
];
}

0 comments on commit febd60d

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