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

Merge pull request #6622 from orklah/return_0

fix @return 0
This commit is contained in:
orklah 2021-10-09 18:25:46 +02:00 committed by GitHub
commit f62c76a334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 3 deletions

View File

@ -348,6 +348,13 @@ class FunctionCallReturnTypeFetcher
return new Type\Union([new Type\Atomic\TIntRange($min, null)]);
}
if ($atomic_types['array'] instanceof Type\Atomic\TArray
&& $atomic_types['array']->type_params[0]->isEmpty()
&& $atomic_types['array']->type_params[1]->isEmpty()
) {
return Type::getInt(false, 0);
}
return new Type\Union([
new Type\Atomic\TLiteralInt(0),
new Type\Atomic\TPositiveInt

View File

@ -543,13 +543,13 @@ class FunctionLikeDocblockParser
foreach ($return_specials as $offset => $return_block) {
$return_lines = explode("\n", $return_block);
if (!trim($return_lines[0])) {
if (trim($return_lines[0]) === '') {
return;
}
$return_block = trim($return_block);
if (!$return_block) {
if ($return_block === '') {
return;
}

View File

@ -355,7 +355,7 @@ class FunctionLikeDocblockScanner
}
}
if ($docblock_info->return_type) {
if ($docblock_info->return_type !== null) {
self::handleReturn(
$codebase,
$docblock_info,

View File

@ -950,6 +950,15 @@ class ReturnTypeTest extends TestCase
returnsNever();
}'
],
'return0' => [
'<?php
/**
* @return 0
*/
function takesAnInt() {
return 0;
}'
],
];
}