1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Add tests for never return type

This commit is contained in:
tuqqu 2023-10-04 21:18:59 +02:00
parent 2a910d1f17
commit 2bc330976f

View File

@ -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',
],
];
}
}