Skip to content

Commit

Permalink
Merge pull request #6622 from orklah/return_0
Browse files Browse the repository at this point in the history
fix @return 0
  • Loading branch information
orklah committed Oct 9, 2021
2 parents 950b21d + a1df08f commit f62c76a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Expand Up @@ -348,6 +348,13 @@ private static function getReturnTypeFromCallMapWithArgs(
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
Expand Down
Expand Up @@ -543,13 +543,13 @@ private static function extractReturnType(
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;
}

Expand Down
Expand Up @@ -355,7 +355,7 @@ function (FunctionLikeParameter $p): bool {
}
}

if ($docblock_info->return_type) {
if ($docblock_info->return_type !== null) {
self::handleReturn(
$codebase,
$docblock_info,
Expand Down
9 changes: 9 additions & 0 deletions tests/ReturnTypeTest.php
Expand Up @@ -950,6 +950,15 @@ function foo() : bool {
returnsNever();
}'
],
'return0' => [
'<?php
/**
* @return 0
*/
function takesAnInt() {
return 0;
}'
],
];
}

Expand Down

0 comments on commit f62c76a

Please sign in to comment.