1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix more try/catch stuff

This commit is contained in:
Matthew Brown 2019-11-12 00:52:10 -05:00
parent 51557c44ea
commit b1aae0d1a5
3 changed files with 20 additions and 7 deletions

View File

@ -372,12 +372,6 @@ class TryAnalyzer
);
if ($context->collect_references && $catch_actions[$i] !== [ScopeAnalyzer::ACTION_END]) {
foreach ($context->unreferenced_vars as $var_id => $_) {
if (!isset($catch_context->unreferenced_vars[$var_id])) {
unset($context->unreferenced_vars[$var_id]);
}
}
$newly_unreferenced_vars = array_merge(
$newly_unreferenced_vars,
array_diff_key(

View File

@ -1223,7 +1223,7 @@ class FunctionTemplateTest extends TestCase
return $callback();
}
makeResultSet([A::class, "returnsObjectOrNull"]);',
makeResultSet([B::class, "returnsObjectOrNull"]);',
'error_message' => 'InvalidArgument',
],
'templateInvokeArg' => [

View File

@ -1232,6 +1232,25 @@ class UnusedVariableTest extends TestCase
}
}'
],
'usedVarInCatchAndAfter' => [
'<?php
function foo() : void {
if (rand(0, 1)) {
throw new \Exception("bad");
}
}
$a = null;
try {
foo();
$a = "hello";
} catch (\Exception $e) {
echo $a;
}
echo $a;'
],
];
}