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

Mark variables in throw arguments as used (#5166)

Fixes vimeo/psalm#5164
This commit is contained in:
Bruce Weirdan 2021-02-07 05:07:01 +02:00 committed by GitHub
parent d740c1679c
commit b72c5a0fa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -425,7 +425,8 @@ class VariableFetchAnalyzer
&& ($context->inside_call
|| $context->inside_conditional
|| $context->inside_use
|| $context->inside_isset)
|| $context->inside_isset
|| $context->inside_throw)
) {
if (!$stmt_type->parent_nodes) {
$assignment_node = DataFlowNode::getForAssignment(

View File

@ -2300,6 +2300,23 @@ class UnusedVariableTest extends TestCase
}
}'
],
'usedThrow' => [
'<?php
function f(Exception $e): void {
throw $e;
}
',
],
'usedThrowInReturnedCallable' => [
'<?php
function createFailingFunction(RuntimeException $exception): Closure
{
return static function () use ($exception): void {
throw $exception;
};
}
',
]
];
}