From 413f1d6ce3e821d2d6676f781d904ca85b371365 Mon Sep 17 00:00:00 2001 From: tuqqu Date: Wed, 4 Oct 2023 20:51:31 +0200 Subject: [PATCH 1/3] Fix error message for returning function with never return type --- src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index 5cfd1b176..b41ba69ec 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -197,6 +197,7 @@ class ReturnTypeAnalyzer ) ) && !$return_type->isVoid() + && !$return_type->isNever() && !$inferred_yield_types && (!$function_like_storage || !$function_like_storage->has_yield) && $function_returns_implicitly From 2a910d1f179a497524e0d6f64eeb36935a20d49a Mon Sep 17 00:00:00 2001 From: tuqqu Date: Wed, 4 Oct 2023 21:00:04 +0200 Subject: [PATCH 2/3] Changed error message for never return error --- src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index b41ba69ec..15ec85e39 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -223,7 +223,7 @@ class ReturnTypeAnalyzer ) { if (IssueBuffer::accepts( new InvalidReturnType( - $cased_method_id . ' is not expected to return any values but it does, ' + $cased_method_id . ' is not expected to return, but it does, ' . 'either implicitly or explicitly', $return_type_location, ), From 2bc330976f87092d4b39275a03168b92c4f2fefe Mon Sep 17 00:00:00 2001 From: tuqqu Date: Wed, 4 Oct 2023 21:18:59 +0200 Subject: [PATCH 3/3] Add tests for never return type --- tests/ReturnTypeTest.php | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/ReturnTypeTest.php b/tests/ReturnTypeTest.php index 2557fdf8a..3bc88b760 100644 --- a/tests/ReturnTypeTest.php +++ b/tests/ReturnTypeTest.php @@ -1279,6 +1279,26 @@ class ReturnTypeTest extends TestCase return $t; }', ], + 'neverReturnType' => [ + 'code' => ' [], + 'ignored_issues' => [], + 'php_version' => '8.1', + ], ]; } @@ -1807,6 +1827,36 @@ class ReturnTypeTest extends TestCase 'ignored_issues' => [], 'php_version' => '8.0', ], + 'implicitReturnFromFunctionWithNeverReturnType' => [ + 'code' => <<<'PHP' + 'InvalidReturnType', + 'ignored_issues' => [], + 'php_version' => '8.1', + ], + 'implicitReturnFromFunctionWithNeverReturnType2' => [ + 'code' => <<<'PHP' + 'InvalidReturnType', + 'ignored_issues' => [], + 'php_version' => '8.1', + ], ]; } }