1
0
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:
Matthew Brown 2019-05-14 21:22:29 -04:00
parent 7f4173efc5
commit 1c10ae11bf
3 changed files with 24 additions and 1 deletions

View File

@ -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]);

View File

@ -563,7 +563,7 @@ class ReturnTypeTest extends TestCase
class B extends A {
/**
* @return no-return
* @return never-returns
*/
public function foo() {
exit();

View File

@ -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);'
],
];
}