Skip to content

Commit

Permalink
Mark variables in throw arguments as used (#5166)
Browse files Browse the repository at this point in the history
Fixes #5164
  • Loading branch information
weirdan committed Feb 7, 2021
1 parent d740c16 commit b72c5a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -425,7 +425,8 @@ private static function addDataFlowToVariable(
&& ($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(
Expand Down
17 changes: 17 additions & 0 deletions tests/UnusedVariableTest.php
Expand Up @@ -2300,6 +2300,23 @@ function takesResults(array $arr) : void {
}
}'
],
'usedThrow' => [
'<?php
function f(Exception $e): void {
throw $e;
}
',
],
'usedThrowInReturnedCallable' => [
'<?php
function createFailingFunction(RuntimeException $exception): Closure
{
return static function () use ($exception): void {
throw $exception;
};
}
',
]
];
}

Expand Down

0 comments on commit b72c5a0

Please sign in to comment.