File: comparable_unsupported.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (66 lines) | stat: -rw-r--r-- 2,698 bytes parent folder | download
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'}}
}