[Constraint solver] Delay Sendable on static method references involving possibly-nonsendable metatypes

Thank you, Pavel!

(cherry picked from commit 88d630446c)
This commit is contained in:
Doug Gregor
2025-04-14 10:19:11 -07:00
parent 89f246985e
commit 271eebbb87
2 changed files with 43 additions and 11 deletions

View File

@@ -10565,26 +10565,34 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
if (Context.LangOpts.hasFeature(Feature::InferSendableFromCaptures)) {
auto shouldCheckSendabilityOfBase = [&]() {
if (!Context.getProtocol(KnownProtocolKind::Sendable))
return false;
return Type();
return llvm::any_of(lookup, [&](const auto &result) {
for (const auto &result : lookup) {
auto decl = result.getValueDecl();
if (!isa_and_nonnull<FuncDecl>(decl))
return false;
continue;
if (!decl->isInstanceMember())
return false;
if (!decl->isInstanceMember() &&
!decl->getDeclContext()->getSelfProtocolDecl())
continue;
auto hasAppliedSelf = decl->hasCurriedSelf() &&
doesMemberRefApplyCurriedSelf(baseObjTy, decl);
auto numApplies = getNumApplications(hasAppliedSelf, functionRefInfo);
return numApplies < decl->getNumCurryLevels();
});
if (numApplies >= decl->getNumCurryLevels())
continue;
return decl->isInstanceMember()
? instanceTy
: MetatypeType::get(instanceTy);
}
return Type();
};
if (shouldCheckSendabilityOfBase()) {
if (Type baseTyToCheck = shouldCheckSendabilityOfBase()) {
auto sendableProtocol = Context.getProtocol(KnownProtocolKind::Sendable);
auto baseConformance = lookupConformance(instanceTy, sendableProtocol);
auto baseConformance = lookupConformance(baseTyToCheck, sendableProtocol);
if (llvm::any_of(
baseConformance.getConditionalRequirements(),
@@ -10593,8 +10601,10 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
return false;
return (req.getFirstType()->hasTypeVariable() &&
req.getProtocolDecl()->isSpecificProtocol(
KnownProtocolKind::Sendable));
(req.getProtocolDecl()->isSpecificProtocol(
KnownProtocolKind::Sendable) ||
req.getProtocolDecl()->isSpecificProtocol(
KnownProtocolKind::SendableMetatype)));
})) {
result.OverallResult = MemberLookupResult::Unsolved;
return result;