Skip to content

Commit

Permalink
Disallow never type for parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
tuqqu committed Oct 8, 2023
1 parent 16be90c commit a4cebb2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions tests/FunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3031,6 +3031,17 @@ function hasZeroByteOffset(string $s) : bool {
}',
'error_message' => 'InvalidScalarArgument',
],
'disallowNeverTypeForParam' => [
'code' => '<?php
function foo(never $_): void
{
return;
}
',
'error_message' => 'ReservedWord',
'ignored_issues' => [],
'php_version' => '8.1',
],
];
}

Expand Down

0 comments on commit a4cebb2

Please sign in to comment.