@@ -68,9 +68,18 @@ void ConformanceLookupTable::ConformanceEntry::markSupersededBy(
68
68
SupersededBy = entry;
69
69
70
70
if (diagnose) {
71
+ // If an unavailable Sendable conformance is superseded by a
72
+ // retroactive one in the client, we need to record this error
73
+ // at the client decl context.
74
+ auto *dc = getDeclContext ();
75
+ if (getProtocol ()->isMarkerProtocol () && isFixed () &&
76
+ !entry->isFixed ()) {
77
+ dc = entry->getDeclContext ();
78
+ }
79
+
71
80
// Record the problem in the conformance table. We'll
72
81
// diagnose these in semantic analysis.
73
- table.AllSupersededDiagnostics [getDeclContext () ].push_back (this );
82
+ table.AllSupersededDiagnostics [dc ].push_back (this );
74
83
}
75
84
}
76
85
@@ -258,14 +267,6 @@ void ConformanceLookupTable::inheritConformances(ClassDecl *classDecl,
258
267
auto addInheritedConformance = [&](ConformanceEntry *entry) {
259
268
auto protocol = entry->getProtocol ();
260
269
261
- // Don't add unavailable conformances.
262
- if (auto dc = entry->Source .getDeclContext ()) {
263
- if (auto ext = dyn_cast<ExtensionDecl>(dc)) {
264
- if (AvailableAttr::isUnavailable (ext))
265
- return ;
266
- }
267
- }
268
-
269
270
// Don't add redundant conformances here. This is merely an
270
271
// optimization; resolveConformances() would zap the duplicates
271
272
// anyway.
@@ -613,30 +614,23 @@ ConformanceLookupTable::Ordering ConformanceLookupTable::compareConformances(
613
614
// same conformance, this silently takes the class and drops the extension.
614
615
if (lhs->getDeclContext ()->isAlwaysAvailableConformanceContext () !=
615
616
rhs->getDeclContext ()->isAlwaysAvailableConformanceContext ()) {
617
+ // Diagnose conflicting marker protocol conformances that differ in
618
+ // un-availability.
619
+ diagnoseSuperseded = lhs->getProtocol ()->isMarkerProtocol ();
620
+
616
621
return (lhs->getDeclContext ()->isAlwaysAvailableConformanceContext ()
617
622
? Ordering::Before
618
623
: Ordering::After);
619
624
}
620
625
621
626
// If one entry is fixed and the other is not, we have our answer.
622
627
if (lhs->isFixed () != rhs->isFixed ()) {
623
- auto isReplaceableOrMarker = [](ConformanceEntry *entry) -> bool {
624
- ConformanceEntryKind kind = entry->getRankingKind ();
625
- if (isReplaceable (kind))
626
- return true ;
627
-
628
- // Allow replacement of an explicit conformance to a marker protocol.
629
- // (This permits redundant explicit declarations of `Sendable`.)
630
- return (kind == ConformanceEntryKind::Explicit
631
- && entry->getProtocol ()->isMarkerProtocol ());
632
- };
633
-
634
628
// If the non-fixed conformance is not replaceable, we have a failure to
635
629
// diagnose.
636
630
// FIXME: We should probably diagnose if they have different constraints.
637
- diagnoseSuperseded = (lhs->isFixed () && !isReplaceableOrMarker (rhs)) ||
638
- (rhs->isFixed () && !isReplaceableOrMarker (lhs));
639
-
631
+ diagnoseSuperseded = (lhs->isFixed () && !isReplaceable (rhs-> getRankingKind () )) ||
632
+ (rhs->isFixed () && !isReplaceable (lhs-> getRankingKind () ));
633
+
640
634
return lhs->isFixed () ? Ordering::Before : Ordering::After;
641
635
}
642
636
@@ -879,8 +873,6 @@ DeclContext *ConformanceLookupTable::getConformingContext(
879
873
return nullptr ;
880
874
auto inheritedConformance = module ->lookupConformance (
881
875
superclassTy, protocol, /* allowMissing=*/ false );
882
- if (inheritedConformance.hasUnavailableConformance ())
883
- inheritedConformance = ProtocolConformanceRef::forInvalid ();
884
876
if (inheritedConformance)
885
877
return superclassDecl;
886
878
} while ((superclassDecl = superclassDecl->getSuperclassDecl ()));
@@ -1146,9 +1138,17 @@ void ConformanceLookupTable::lookupConformances(
1146
1138
if (diagnostics) {
1147
1139
auto knownDiags = AllSupersededDiagnostics.find (dc);
1148
1140
if (knownDiags != AllSupersededDiagnostics.end ()) {
1149
- for (const auto *entry : knownDiags->second ) {
1141
+ for (auto *entry : knownDiags->second ) {
1150
1142
ConformanceEntry *supersededBy = entry->getSupersededBy ();
1151
1143
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