@@ -70,18 +70,9 @@ void ConformanceLookupTable::ConformanceEntry::markSupersededBy(
7070 SupersededBy = entry;
7171
7272 if (diagnose) {
73- // If an unavailable Sendable conformance is superseded by a
74- // retroactive one in the client, we need to record this error
75- // at the client decl context.
76- auto *dc = getDeclContext ();
77- if (getProtocol ()->isMarkerProtocol () && isFixed () &&
78- !entry->isFixed ()) {
79- dc = entry->getDeclContext ();
80- }
81-
8273 // Record the problem in the conformance table. We'll
8374 // diagnose these in semantic analysis.
84- table.AllSupersededDiagnostics [dc ].push_back (this );
75+ table.AllSupersededDiagnostics [getDeclContext () ].push_back (this );
8576 }
8677}
8778
@@ -269,6 +260,14 @@ void ConformanceLookupTable::inheritConformances(ClassDecl *classDecl,
269260 auto addInheritedConformance = [&](ConformanceEntry *entry) {
270261 auto protocol = entry->getProtocol ();
271262
263+ // Don't add unavailable conformances.
264+ if (auto dc = entry->Source .getDeclContext ()) {
265+ if (auto ext = dyn_cast<ExtensionDecl>(dc)) {
266+ if (AvailableAttr::isUnavailable (ext))
267+ return ;
268+ }
269+ }
270+
272271 // Don't add redundant conformances here. This is merely an
273272 // optimization; resolveConformances() would zap the duplicates
274273 // anyway.
@@ -616,23 +615,30 @@ ConformanceLookupTable::Ordering ConformanceLookupTable::compareConformances(
616615 // same conformance, this silently takes the class and drops the extension.
617616 if (lhs->getDeclContext ()->isAlwaysAvailableConformanceContext () !=
618617 rhs->getDeclContext ()->isAlwaysAvailableConformanceContext ()) {
619- // Diagnose conflicting marker protocol conformances that differ in
620- // un-availability.
621- diagnoseSuperseded = lhs->getProtocol ()->isMarkerProtocol ();
622-
623618 return (lhs->getDeclContext ()->isAlwaysAvailableConformanceContext ()
624619 ? Ordering::Before
625620 : Ordering::After);
626621 }
627622
628623 // If one entry is fixed and the other is not, we have our answer.
629624 if (lhs->isFixed () != rhs->isFixed ()) {
625+ auto isReplaceableOrMarker = [](ConformanceEntry *entry) -> bool {
626+ ConformanceEntryKind kind = entry->getRankingKind ();
627+ if (isReplaceable (kind))
628+ return true ;
629+
630+ // Allow replacement of an explicit conformance to a marker protocol.
631+ // (This permits redundant explicit declarations of `Sendable`.)
632+ return (kind == ConformanceEntryKind::Explicit
633+ && entry->getProtocol ()->isMarkerProtocol ());
634+ };
635+
630636 // If the non-fixed conformance is not replaceable, we have a failure to
631637 // diagnose.
632638 // FIXME: We should probably diagnose if they have different constraints.
633- diagnoseSuperseded = (lhs->isFixed () && !isReplaceable (rhs-> getRankingKind () )) ||
634- (rhs->isFixed () && !isReplaceable (lhs-> getRankingKind () ));
635-
639+ diagnoseSuperseded = (lhs->isFixed () && !isReplaceableOrMarker (rhs)) ||
640+ (rhs->isFixed () && !isReplaceableOrMarker (lhs));
641+
636642 return lhs->isFixed () ? Ordering::Before : Ordering::After;
637643 }
638644
@@ -874,6 +880,8 @@ DeclContext *ConformanceLookupTable::getConformingContext(
874880 return nullptr ;
875881 auto inheritedConformance = swift::lookupConformance (
876882 superclassTy, protocol, /* allowMissing=*/ false );
883+ if (inheritedConformance.hasUnavailableConformance ())
884+ inheritedConformance = ProtocolConformanceRef::forInvalid ();
877885 if (inheritedConformance)
878886 return superclassDecl;
879887 } while ((superclassDecl = superclassDecl->getSuperclassDecl ()));
@@ -1138,17 +1146,9 @@ void ConformanceLookupTable::lookupConformances(
11381146 if (diagnostics) {
11391147 auto knownDiags = AllSupersededDiagnostics.find (dc);
11401148 if (knownDiags != AllSupersededDiagnostics.end ()) {
1141- for (auto *entry : knownDiags->second ) {
1149+ for (const auto *entry : knownDiags->second ) {
11421150 ConformanceEntry *supersededBy = entry->getSupersededBy ();
11431151
1144- // Diagnose the client conformance as superseded.
1145- auto *definingModule = nominal->getParentModule ();
1146- if (entry->getDeclContext ()->getParentModule () == definingModule &&
1147- supersededBy->getDeclContext ()->getParentModule () != definingModule) {
1148- supersededBy = entry;
1149- entry = entry->getSupersededBy ();
1150- }
1151-
11521152 diagnostics->push_back ({entry->getProtocol (),
11531153 entry->getDeclaredLoc (),
11541154 entry->getKind (),
0 commit comments