Skip to content

Commit

Permalink
Merge pull request #6952 from orklah/null_propagation_in_return
Browse files Browse the repository at this point in the history
fix null propagation in return
  • Loading branch information
orklah committed Nov 21, 2021
2 parents f2aa9ca + 6bdadfe commit 4613927
Showing 1 changed file with 12 additions and 7 deletions.
Expand Up @@ -948,18 +948,23 @@ private static function handleReturn(
}
}

// if the signature type contains null, we add null into the final return type too
if ($storage->signature_return_type->isNullable()
&& !$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());
//don't add null to final type if signature type don't match the docblock type
// however, we can't check for object types at this point (#6931), so we'll assume it's ok
if ($storage->return_type->hasObjectType() ||
UnionTypeComparator::isContainedBy(
$codebase,
$storage->return_type,
$storage->signature_return_type
)
) {
$storage->return_type->addType(new Type\Atomic\TNull());
}
}
}

Expand Down

0 comments on commit 4613927

Please sign in to comment.