mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Merge pull request #10254 from tuqqu/never-function-return-error-message
Fix error message for implicitly returning functions with `never` return type
This commit is contained in:
commit
3f7306d8df
@ -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
|
||||
@ -222,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,
|
||||
),
|
||||
|
@ -1279,6 +1279,26 @@ class ReturnTypeTest extends TestCase
|
||||
return $t;
|
||||
}',
|
||||
],
|
||||
'neverReturnType' => [
|
||||
'code' => '<?php
|
||||
function exitProgram(bool $die): never
|
||||
{
|
||||
if ($die) {
|
||||
die;
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
function throwError(): never
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
',
|
||||
'assertions' => [],
|
||||
'ignored_issues' => [],
|
||||
'php_version' => '8.1',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -1807,6 +1827,36 @@ class ReturnTypeTest extends TestCase
|
||||
'ignored_issues' => [],
|
||||
'php_version' => '8.0',
|
||||
],
|
||||
'implicitReturnFromFunctionWithNeverReturnType' => [
|
||||
'code' => <<<'PHP'
|
||||
<?php
|
||||
function foo(): never
|
||||
{
|
||||
if (rand(0, 1)) {
|
||||
exit();
|
||||
}
|
||||
}
|
||||
PHP,
|
||||
'error_message' => 'InvalidReturnType',
|
||||
'ignored_issues' => [],
|
||||
'php_version' => '8.1',
|
||||
],
|
||||
'implicitReturnFromFunctionWithNeverReturnType2' => [
|
||||
'code' => <<<'PHP'
|
||||
<?php
|
||||
function foo(bool $x): never
|
||||
{
|
||||
while (true) {
|
||||
if ($x) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
PHP,
|
||||
'error_message' => 'InvalidReturnType',
|
||||
'ignored_issues' => [],
|
||||
'php_version' => '8.1',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user