mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #1580 - look for no-returns in try/catch statements
This commit is contained in:
parent
7f4173efc5
commit
1c10ae11bf
@ -291,6 +291,13 @@ class TryAnalyzer
|
||||
|
||||
$statements_analyzer->analyze($catch->stmts, $catch_context);
|
||||
|
||||
// recalculate in case there's a no-return clause
|
||||
$catch_actions[$i] = ScopeAnalyzer::getFinalControlActions(
|
||||
$catch->stmts,
|
||||
$codebase->config->exit_functions,
|
||||
$context->inside_case
|
||||
);
|
||||
|
||||
foreach ($issues_to_suppress as $issue_to_suppress) {
|
||||
if (!in_array($issue_to_suppress, $suppressed_issues, true)) {
|
||||
$statements_analyzer->removeSuppressedIssues([$issue_to_suppress]);
|
||||
|
@ -563,7 +563,7 @@ class ReturnTypeTest extends TestCase
|
||||
|
||||
class B extends A {
|
||||
/**
|
||||
* @return no-return
|
||||
* @return never-returns
|
||||
*/
|
||||
public function foo() {
|
||||
exit();
|
||||
|
@ -205,6 +205,22 @@ class TryCatchTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'noReturnInsideCatch' => [
|
||||
'<?php
|
||||
/**
|
||||
* @return never-returns
|
||||
*/
|
||||
function example() : void {
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
try {
|
||||
$str = "a";
|
||||
} catch (Exception $e) {
|
||||
example();
|
||||
}
|
||||
ord($str);'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user