Skip to content

Commit 903e68b

Browse files
committed
NFC: Test derived Comparable conformances for enums with unavailable cases.
Also, add a FIXME to track improving the diagnostics when derivation of a Comparable conformance is blocked by unavailable enum cases.
1 parent fb2f9bf commit 903e68b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Diff for: lib/Sema/DerivedConformanceComparable.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,7 @@ void DerivedConformance::tryDiagnoseFailedComparableDerivation(
342342
rawType, nominal->getDeclaredInterfaceType(),
343343
comparableProto->getDeclaredInterfaceType());
344344
}
345+
// FIXME: Diagnose potentially unavailable enum elements that are preventing
346+
// Comparable synthesis.
345347
}
346348
}

Diff for: test/decl/protocol/special/comparable/comparable_unsupported.swift

+22
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ enum NotComparableEnumOne: Int, Comparable {
2424
case value
2525
}
2626

27+
// A potentially unavailable (or unconditionally unavailable) enum case prevents
28+
// automatic synthesis of Comparable requirements.
29+
// FIXME: This should be diagnosed explicitly.
30+
31+
enum EnumWithUnavailableCase: Comparable {
32+
// expected-error@-1 {{type 'EnumWithUnavailableCase' does not conform to protocol 'Comparable'}}
33+
case available
34+
35+
@available(*, unavailable)
36+
case unavailable
37+
}
38+
39+
enum EnumWithUnavailableCaseAndAssociatedValue: Comparable {
40+
// expected-error@-1 {{type 'EnumWithUnavailableCaseAndAssociatedValue' does not conform to protocol 'Comparable'}}
41+
enum SomeComparable: Comparable {}
42+
43+
case none
44+
45+
@available(*, unavailable)
46+
case some(SomeComparable)
47+
}
48+
2749
// Automatic synthesis of Comparable requires associated values to be Comparable as well.
2850

2951
enum NotComparableEnumTwo: Comparable {

0 commit comments

Comments
 (0)