Skip to content

Commit

Permalink
Properly fix #1128 with additional check
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed May 20, 2019
1 parent 83a2122 commit 2637156
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Expand Up @@ -51,7 +51,7 @@ public static function analyze(
*/
$context->possibly_thrown_exceptions = [];

if ($all_catches_leave) {
if ($all_catches_leave && !$stmt->finally) {
$try_context = $context;
} else {
$try_context = clone $context;
Expand Down
20 changes: 20 additions & 0 deletions tests/UnusedVariableTest.php
Expand Up @@ -965,6 +965,26 @@ function foo() : void {
}
}'
],
'useTryAssignedVariableInFinallyWhenCatchExits' => [
'<?php
/**
* @return resource
*/
function getStream() {
throw new \Exception();
}
$stream = null;
try {
$stream = getStream();
\file_put_contents("./foobar", $stream);
} catch (\Exception $e) {
throw new \Exception("Something went wrong");
} finally {
\fclose($stream);
}',
],
];
}

Expand Down

0 comments on commit 2637156

Please sign in to comment.