Skip to content

Commit e5af49a

Browse files
committed
AST: Tweak ConformanceLookupTable::compareConformances() some more
If two conformances imply a conformance to the same marker protocol, don't diagnose redundancy if they differ by unavailability. Instead, allow the more available conformance to win. This allows declaring a type that conforms to a protocol that inherits from SendableMetatype, followed by an unavailable Sendable conformance on the same type. Fixes rdar://152509409.
1 parent 96d6eb8 commit e5af49a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/AST/ConformanceLookupTable.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,10 @@ ConformanceLookupTable::Ordering ConformanceLookupTable::compareConformances(
615615
rhs->getDeclContext()->isAlwaysAvailableConformanceContext()) {
616616
// Diagnose conflicting marker protocol conformances that differ in
617617
// un-availability.
618-
diagnoseSuperseded = (lhs->getProtocol()->isMarkerProtocol() &&
619-
isUnavailable(lhs->getDeclContext()) !=
620-
isUnavailable(rhs->getDeclContext()));
618+
diagnoseSuperseded =
619+
(lhs->getProtocol()->isMarkerProtocol() &&
620+
isUnavailable(lhs->getDeclContext()) != isUnavailable(rhs->getDeclContext()) &&
621+
(lhsKind != ConformanceEntryKind::Implied || rhsKind != ConformanceEntryKind::Implied));
621622

622623
return (lhs->getDeclContext()->isAlwaysAvailableConformanceContext()
623624
? Ordering::Before

test/Sema/conformance_availability_implied.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,12 @@ extension Conformer2: Derived1 {
5757
extension Conformer2: Derived2 {
5858
func f() {} // expected-note {{'f()' declared here}}
5959
}
60+
61+
protocol P: MarkerBase {}
62+
63+
struct Conformer3: P {}
64+
65+
@available(*, unavailable)
66+
extension Conformer3: MarkerDerived1 {}
67+
68+
takesMarkerBase(Conformer3.self)

0 commit comments

Comments
 (0)