Skip to content
Permalink
Browse files

Evaluate finally blocks at the end of every catch

  • Loading branch information
muglug committed Nov 11, 2019
1 parent da03902 commit 51557c44eae8a631c4efc7825be8db419d68e815
Showing with 35 additions and 1 deletion.
  1. +18 −0 src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php
  2. +17 −1 tests/UnusedVariableTest.php
@@ -436,6 +436,24 @@ function ($fq_catch_class) use ($codebase) {
);
}
}
if ($stmt->finally) {
$suppressed_issues = $statements_analyzer->getSuppressedIssues();
foreach ($issues_to_suppress as $issue_to_suppress) {
if (!in_array($issue_to_suppress, $suppressed_issues, true)) {
$statements_analyzer->addSuppressedIssues([$issue_to_suppress]);
}
}
$statements_analyzer->analyze($stmt->finally->stmts, $catch_context);
foreach ($issues_to_suppress as $issue_to_suppress) {
if (!in_array($issue_to_suppress, $suppressed_issues, true)) {
$statements_analyzer->removeSuppressedIssues([$issue_to_suppress]);
}
}
}
}
foreach ($definitely_newly_assigned_var_ids as $var_id => $_) {
@@ -984,7 +984,9 @@ function getStream() {
} catch (\Exception $e) {
throw new \Exception("Something went wrong");
} finally {
\fclose($stream);
if ($stream) {
\fclose($stream);
}
}',
],
'varUsedInloop' => [
@@ -1216,6 +1218,20 @@ function dangerous() : string {
return "hello";
}',
],
'useTryAndCatchAssignedVariableInsideFinally' => [
'<?php
function foo() : void {
try {
// do something dangerous
$a = 5;
} catch (Exception $e) {
$a = 4;
throw new Exception("bad");
} finally {
echo $a;
}
}'
],
];
}

0 comments on commit 51557c4

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