Skip to content

Commit

Permalink
Merge pull request #6187 from orklah/wrong-nullable-type
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan authored Jul 26, 2021
2 parents 03d7617 + 06af927 commit ae0c8f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function getReturnTypes(
} elseif ($stmt->expr instanceof PhpParser\Node\Scalar\String_) {
$return_types[] = Type::getString();
} elseif ($stmt->expr instanceof PhpParser\Node\Scalar\LNumber) {
$return_types[] = Type::getString();
$return_types[] = Type::getInt();
} elseif ($stmt->expr instanceof PhpParser\Node\Expr\ConstFetch) {
if ((string)$stmt->expr->name === 'true') {
$return_types[] = Type::getTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Psalm\Exception\TypeParseTreeException;
use Psalm\Internal\Scanner\FileScanner;
use Psalm\Internal\Scanner\FunctionDocblockComment;
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
use Psalm\Internal\Type\TypeAlias;
use Psalm\Internal\Type\TypeParser;
use Psalm\Internal\Type\TypeTokenizer;
Expand Down Expand Up @@ -908,6 +909,12 @@ private static function handleReturn(
&& !$storage->return_type->isNullable()
&& !$storage->return_type->hasTemplate()
&& !$storage->return_type->hasConditional()
//don't add null to docblock type if it's not contained in signature type
&& UnionTypeComparator::isContainedBy(
$codebase,
$storage->return_type,
$storage->signature_return_type
)
) {
$storage->return_type->addType(new Type\Atomic\TNull());
}
Expand Down

0 comments on commit ae0c8f5

Please sign in to comment.