Skip to content

Commit 5ba80ee

Browse files
committed
Work around issue with inherited Sendable conformance lookup.
Implicit synthesis of `Sendable` conformances for global actor-isolated class types interacts poorly with the conformance lookup table's attempt at modeling inherited conformances, so a `Sendable` conformance will get created and inherited, but is then "missing" when we try to form the actual inherited conformance. The proper fix for this issue is likely to eliminate the modeling of inherited conformances within the conformance lookup table, which introduces a lot of redundance and, apparently, some bugs. For now, patch over the issue to work around a crash. Narrowly works around rdar://81700570.
1 parent 926a59c commit 5ba80ee

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

lib/AST/ConformanceLookupTable.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,30 @@ DeclContext *ConformanceLookupTable::getConformingContext(
798798
// Grab the superclass entry and continue searching for a
799799
// non-inherited conformance.
800800
// FIXME: Ambiguity detection and resolution.
801-
entry = superclassDecl->ConformanceTable->Conformances[protocol].front();
801+
const auto &superclassConformances =
802+
superclassDecl->ConformanceTable->Conformances[protocol];
803+
if (superclassConformances.empty()) {
804+
assert(protocol->isSpecificProtocol(KnownProtocolKind::Sendable));
805+
806+
// Go dig for a superclass that does conform to Sendable.
807+
// FIXME: This is a hack because the inherited conformances aren't
808+
// getting updated properly.
809+
Type classTy = nominal->getDeclaredInterfaceType();
810+
ModuleDecl *module = nominal->getParentModule();
811+
do {
812+
Type superclassTy = classTy->getSuperclassForDecl(superclassDecl);
813+
if (superclassTy->is<ErrorType>())
814+
return nullptr;
815+
auto inheritedConformance = module->lookupConformance(
816+
superclassTy, protocol);
817+
if (inheritedConformance)
818+
return superclassDecl;
819+
} while ((superclassDecl = superclassDecl->getSuperclassDecl()));
820+
821+
return nullptr;
822+
}
823+
824+
entry = superclassConformances.front();
802825
nominal = superclassDecl;
803826
}
804827

0 commit comments

Comments
 (0)