Skip to content

Commit

Permalink
Merge pull request #10266 from tuqqu/never-parameter-type
Browse files Browse the repository at this point in the history
Disallow `never` type for parameters
  • Loading branch information
orklah authored Oct 8, 2023
2 parents 16be90c + a4cebb2 commit cad10a1
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 cad10a1

Please sign in to comment.