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:
parent
574a5530ee
commit
83e22a10f8
@ -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
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user