Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix null propagation in return #6952

Merged
merged 1 commit into from Nov 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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