diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index 936c33571..d2da23b3a 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -399,7 +399,7 @@ class ReturnTypeAnalyzer || ($classlike_storage && $classlike_storage->final) ); - if (!$inferred_return_type_parts + if (!$inferred_return_type->isNever() && !$inferred_yield_types && (!$function_like_storage || !$function_like_storage->has_yield) ) { diff --git a/tests/ReturnTypeTest.php b/tests/ReturnTypeTest.php index 4e6730a65..8dfd89988 100644 --- a/tests/ReturnTypeTest.php +++ b/tests/ReturnTypeTest.php @@ -967,6 +967,17 @@ class ReturnTypeTest extends TestCase exit(1); });' ], + 'ExitInBothBranches' => [ + '