1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #1299 - vars defined in catches before throw are possibly-defined for finally

This commit is contained in:
Matthew Brown 2019-02-09 15:39:30 -05:00
parent 574a5530ee
commit 83e22a10f8
2 changed files with 26 additions and 0 deletions

View File

@ -353,6 +353,11 @@ class TryAnalyzer
}
}
$context->vars_possibly_in_scope = array_merge(
$catch_context->vars_possibly_in_scope,
$context->vars_possibly_in_scope
);
} elseif ($stmt->finally) {
$context->vars_possibly_in_scope = array_merge(
$catch_context->vars_possibly_in_scope,
$context->vars_possibly_in_scope

View File

@ -181,6 +181,27 @@ class TryCatchTest extends TestCase
}
}',
],
'notAlwaysUndefinedVarInFinally' => [
'<?php
function maybeThrows() : void {
if (rand(0, 1)) {
throw new UnexpectedValueException();
}
}
function doTry() : void {
try {
maybeThrows();
return;
} catch (Exception $exception) {
throw $exception;
} finally {
if (isset($exception)) {
echo "here";
}
}
}'
],
];
}