1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Disallow never type for parameters

This commit is contained in:
tuqqu 2023-10-08 20:47:37 +02:00
parent 16be90c351
commit a4cebb2cb8
2 changed files with 22 additions and 0 deletions

View File

@ -1260,6 +1260,17 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
);
}
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,

View File

@ -3031,6 +3031,17 @@ class FunctionCallTest extends TestCase
}',
'error_message' => 'InvalidScalarArgument',
],
'disallowNeverTypeForParam' => [
'code' => '<?php
function foo(never $_): void
{
return;
}
',
'error_message' => 'ReservedWord',
'ignored_issues' => [],
'php_version' => '8.1',
],
];
}