Skip to content

Commit

Permalink
Fix #1580 - look for no-returns in try/catch statements
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed May 15, 2019
1 parent 7f4173e commit 1c10ae1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php
Expand Up @@ -291,6 +291,13 @@ function ($fq_catch_class) use ($codebase) {


$statements_analyzer->analyze($catch->stmts, $catch_context); $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) { foreach ($issues_to_suppress as $issue_to_suppress) {
if (!in_array($issue_to_suppress, $suppressed_issues, true)) { if (!in_array($issue_to_suppress, $suppressed_issues, true)) {
$statements_analyzer->removeSuppressedIssues([$issue_to_suppress]); $statements_analyzer->removeSuppressedIssues([$issue_to_suppress]);
Expand Down
2 changes: 1 addition & 1 deletion tests/ReturnTypeTest.php
Expand Up @@ -563,7 +563,7 @@ public function foo() {
class B extends A { class B extends A {
/** /**
* @return no-return * @return never-returns
*/ */
public function foo() { public function foo() {
exit(); exit();
Expand Down
16 changes: 16 additions & 0 deletions tests/TryCatchTest.php
Expand Up @@ -205,6 +205,22 @@ function doTry() : void {
} }
}', }',
], ],
'noReturnInsideCatch' => [
'<?php
/**
* @return never-returns
*/
function example() : void {
throw new Exception();
}
try {
$str = "a";
} catch (Exception $e) {
example();
}
ord($str);'
],
]; ];
} }


Expand Down

0 comments on commit 1c10ae1

Please sign in to comment.