@@ -70,18 +70,9 @@ void ConformanceLookupTable::ConformanceEntry::markSupersededBy(
70
70
SupersededBy = entry;
71
71
72
72
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
-
82
73
// Record the problem in the conformance table. We'll
83
74
// diagnose these in semantic analysis.
84
- table.AllSupersededDiagnostics [dc ].push_back (this );
75
+ table.AllSupersededDiagnostics [getDeclContext () ].push_back (this );
85
76
}
86
77
}
87
78
@@ -269,6 +260,14 @@ void ConformanceLookupTable::inheritConformances(ClassDecl *classDecl,
269
260
auto addInheritedConformance = [&](ConformanceEntry *entry) {
270
261
auto protocol = entry->getProtocol ();
271
262
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
+
272
271
// Don't add redundant conformances here. This is merely an
273
272
// optimization; resolveConformances() would zap the duplicates
274
273
// anyway.
@@ -616,23 +615,30 @@ ConformanceLookupTable::Ordering ConformanceLookupTable::compareConformances(
616
615
// same conformance, this silently takes the class and drops the extension.
617
616
if (lhs->getDeclContext ()->isAlwaysAvailableConformanceContext () !=
618
617
rhs->getDeclContext ()->isAlwaysAvailableConformanceContext ()) {
619
- // Diagnose conflicting marker protocol conformances that differ in
620
- // un-availability.
621
- diagnoseSuperseded = lhs->getProtocol ()->isMarkerProtocol ();
622
-
623
618
return (lhs->getDeclContext ()->isAlwaysAvailableConformanceContext ()
624
619
? Ordering::Before
625
620
: Ordering::After);
626
621
}
627
622
628
623
// If one entry is fixed and the other is not, we have our answer.
629
624
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
+
630
636
// If the non-fixed conformance is not replaceable, we have a failure to
631
637
// diagnose.
632
638
// 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
+
636
642
return lhs->isFixed () ? Ordering::Before : Ordering::After;
637
643
}
638
644
@@ -874,6 +880,8 @@ DeclContext *ConformanceLookupTable::getConformingContext(
874
880
return nullptr ;
875
881
auto inheritedConformance = swift::lookupConformance (
876
882
superclassTy, protocol, /* allowMissing=*/ false );
883
+ if (inheritedConformance.hasUnavailableConformance ())
884
+ inheritedConformance = ProtocolConformanceRef::forInvalid ();
877
885
if (inheritedConformance)
878
886
return superclassDecl;
879
887
} while ((superclassDecl = superclassDecl->getSuperclassDecl ()));
@@ -1138,17 +1146,9 @@ void ConformanceLookupTable::lookupConformances(
1138
1146
if (diagnostics) {
1139
1147
auto knownDiags = AllSupersededDiagnostics.find (dc);
1140
1148
if (knownDiags != AllSupersededDiagnostics.end ()) {
1141
- for (auto *entry : knownDiags->second ) {
1149
+ for (const auto *entry : knownDiags->second ) {
1142
1150
ConformanceEntry *supersededBy = entry->getSupersededBy ();
1143
1151
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
-
1152
1152
diagnostics->push_back ({entry->getProtocol (),
1153
1153
entry->getDeclaredLoc (),
1154
1154
entry->getKind (),
0 commit comments