1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown
// Automatic synthesis of Comparable is only supported for enums for now.
struct NotComparableStruct: Comparable {
// expected-error@-1 {{type 'NotComparableStruct' does not conform to protocol 'Comparable'}}
// expected-note@-2 {{automatic synthesis of 'Comparable' is not supported for struct declarations}}
var value = 0
}
class NotComparableClass: Comparable {
// expected-error@-1 {{type 'NotComparableClass' does not conform to protocol 'Comparable'}}
// expected-note@-2 {{automatic synthesis of 'Comparable' is not supported for class declarations}}
// expected-error@-3 {{type 'NotComparableClass' does not conform to protocol 'Equatable'}}
// expected-note@-4 {{automatic synthesis of 'Equatable' is not supported for class declarations}}
var value = 1
}
// Automatic synthesis of Comparable requires enum without raw type.
enum NotComparableEnumOne: Int, Comparable {
// expected-error@-1 {{type 'NotComparableEnumOne' does not conform to protocol 'Comparable'}}
// expected-note@-2 {{enum declares raw type 'Int', preventing synthesized conformance of 'NotComparableEnumOne' to 'Comparable'}}
case value
}
// A potentially unavailable (or unconditionally unavailable) enum case prevents
// automatic synthesis of Comparable requirements.
// FIXME: This should be diagnosed explicitly.
enum EnumWithUnavailableCase: Comparable {
// expected-error@-1 {{type 'EnumWithUnavailableCase' does not conform to protocol 'Comparable'}}
case available
@available(*, unavailable)
case unavailable
}
enum EnumWithUnavailableCaseAndAssociatedValue: Comparable {
// expected-error@-1 {{type 'EnumWithUnavailableCaseAndAssociatedValue' does not conform to protocol 'Comparable'}}
enum SomeComparable: Comparable {}
case none
@available(*, unavailable)
case some(SomeComparable)
}
enum EnumWithUnavailableCaseAndAssociatedValue2: Comparable {
// expected-error@-1 {{type 'EnumWithUnavailableCaseAndAssociatedValue2' does not conform to protocol 'Comparable'}}
enum SomeComparable: Comparable {}
case this(SomeComparable)
@available(*, unavailable)
case that(SomeComparable)
}
// Automatic synthesis of Comparable requires associated values to be Comparable as well.
enum NotComparableEnumTwo: Comparable {
// expected-error@-1 {{type 'NotComparableEnumTwo' does not conform to protocol 'Comparable'}}
struct NotComparable: Equatable {}
case value(NotComparable)
// expected-note@-1 {{associated value type 'NotComparableEnumTwo.NotComparable' does not conform to protocol 'Comparable', preventing synthesized conformance of 'NotComparableEnumTwo' to 'Comparable'}}
}
|