From a4cebb2cb85b78825c4eb5b31c3647d012aeb6d2 Mon Sep 17 00:00:00 2001 From: tuqqu Date: Sun, 8 Oct 2023 20:47:37 +0200 Subject: [PATCH] Disallow never type for parameters --- src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php | 11 +++++++++++ tests/FunctionCallTest.php | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index 3c0b6f2bd54..4e93704e2c3 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -1260,6 +1260,17 @@ private function processParams( ); } + if ($param_type->isNever()) { + IssueBuffer::maybeAdd( + new ReservedWord( + 'Parameter cannot be never', + $function_param->type_location, + 'never', + ), + $this->suppressed_issues, + ); + } + if ($param_type->check( $this->source, $function_param->type_location, diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index 23f9dcb0865..f712af9dacd 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -3031,6 +3031,17 @@ function hasZeroByteOffset(string $s) : bool { }', 'error_message' => 'InvalidScalarArgument', ], + 'disallowNeverTypeForParam' => [ + 'code' => ' 'ReservedWord', + 'ignored_issues' => [], + 'php_version' => '8.1', + ], ]; }