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

Fix #5540 - function is used inside throw expression

This commit is contained in:
Matt Brown 2021-03-31 10:03:08 -04:00
parent 59b7de5647
commit 150dd00060
2 changed files with 19 additions and 6 deletions

View File

@ -1008,11 +1008,12 @@ class FunctionCallAnalyzer extends CallAnalyzer
* If a function is pure, and has the return type of 'no-return',
* it's okay to dismiss it's return value.
*/
if (!$context->inside_assignment &&
!$context->inside_call &&
!$context->inside_use &&
!self::callUsesByReferenceArguments($function_call_info, $stmt) &&
!(
if (!$context->inside_assignment
&& !$context->inside_call
&& !$context->inside_use
&& !$context->inside_throw
&& !self::callUsesByReferenceArguments($function_call_info, $stmt)
&& !(
$function_call_info->function_storage &&
$function_call_info->function_storage->return_type &&
$function_call_info->function_storage->return_type->isNever()

View File

@ -892,7 +892,19 @@ class UnusedCodeTest extends TestCase
return $f;
}',
]
],
'functionCallUsedInThrow' => [
'<?php
/**
* @psalm-pure
*/
function getException(): \Exception
{
return new \Exception();
}
throw getException();'
],
];
}