File: failure.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 (263 lines) | stat: -rw-r--r-- 10,220 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// RUN: %target-typecheck-verify-swift

protocol P1 {
  func foo() // expected-note {{protocol requires function 'foo()'}}
  func bar() // okay
}

extension P1 {
  func bar() {} // okay
}

struct P1Conformer : P1 {} // expected-error {{does not conform}}


protocol P2 {
  func foo() // expected-note {{protocol requires function 'foo()'}}
  func bar() // expected-note {{protocol requires function 'bar()'}}
}
protocol P2Helper {}

extension P2 where Self : P2Helper {
  func bar() {} // expected-note {{candidate}}
}

struct P2Conformer : P2 {} // expected-error {{does not conform}}


protocol P3 {
  func foo() // expected-note {{protocol requires function 'foo()'}}
  func bar() // okay
  func baz() -> Baz
  associatedtype Baz
}

extension P3 {
  func bar() {} // okay
}

struct P3Conformer : P3 { // expected-error {{does not conform}}
  func baz() -> Int { return 0 }
}


protocol P4 {
  func foo() // expected-note {{protocol requires function 'foo()'}}
  func bar() // expected-note {{protocol requires function 'bar()'}}
  func baz() -> Baz // okay
  associatedtype Baz
}
protocol P4Helper {}

extension P4 where Self : P4Helper {
  func bar() {} // expected-note {{candidate}}
}

struct P4Conformer : P4 { // expected-error {{does not conform}}
  func baz() -> Int { return 0 }
}


protocol P5 {
  associatedtype Foo
  func foo() -> Foo // expected-note {{protocol requires function 'foo()'}}
  func bar() -> Foo // okay
  func baz() -> Foo // okay
}

extension P5 {
  func bar() -> Foo { return foo() } // okay
}

struct P5Conformer : P5 { // expected-error {{does not conform}}
  func baz() -> Int { return 0 }
}


protocol P6Base {
  associatedtype Foo // expected-note{{protocol requires nested type 'Foo'; add nested type 'Foo' for conformance}}
  func foo()
  func bar() -> Foo
}
extension P6Base {
}
protocol P6 : P6Base {
  associatedtype Bar // expected-note {{protocol requires nested type 'Bar'}}
}
extension P6 {
  func bar() -> Bar? { return nil }
}

struct P6Conformer : P6 { // expected-error 2 {{does not conform}}
  func foo() {}
}

// rdar://problem/23033862
// expected-error@+2{{type 'A' does not conform to protocol 'OptionSet'}}
// expected-error@+1{{type 'A' does not conform to protocol 'RawRepresentable'}}
struct A: OptionSet {
  let rawValue = 0
  init() { }
}

// Type witness cannot have its own generic parameters
// FIXME: Crappy diagnostic
protocol PA {
  associatedtype A // expected-note 3 {{protocol requires nested type 'A'; add nested type 'A' for conformance}}
}

struct BadCase1 : PA { // expected-error {{type 'BadCase1' does not conform to protocol 'PA'}}
  struct A<T> {}
}

struct BadCase2 : PA { // expected-error {{type 'BadCase2' does not conform to protocol 'PA'}}
  typealias A<T> = T
}

// Variation on the above
struct G<T> {}

struct BadCase3 : PA { // expected-error {{type 'BadCase3' does not conform to protocol 'PA'}}
  typealias A = G
}

// rdar://problem/32215763
extension UInt32: @retroactive ExpressibleByStringLiteral {}
// expected-error@-1 {{type 'UInt32' does not conform to protocol 'ExpressibleByStringLiteral'}}
// expected-error@-2 {{type 'UInt32' does not conform to protocol 'ExpressibleByExtendedGraphemeClusterLiteral'}}
// expected-error@-3 {{type 'UInt32' does not conform to protocol 'ExpressibleByUnicodeScalarLiteral'}}

// After successfully type-checking this (due to the presumption of
// the type actually conforming), do not crash when failing to find
// the associated witness type.
let diagnose: UInt32 = "reta"

// Test that we attempt to resolve a value witness unless mapping its interface
// type into the conformance context produces an invalid type.
protocol P7 {
  associatedtype A: Sequence // expected-note {{protocol requires nested type 'A'; add nested type 'A' for conformance}}

  subscript(subscript1 _: A) -> Never { get }
  subscript<T>(subscript2 _: T) -> Never where T: Sequence, T.Element == A { get }
  // expected-note@-1 {{protocol requires subscript with type '<T> (subscript2: T) -> Never'; add a stub for conformance}}

  func method1(_: A)
  func method2() -> A.Element
  func method3<T>(_: T) where T: Sequence, T.Element == A
  // expected-note@-1 {{protocol requires function 'method3' with type '<T> (T) -> ()'; add a stub for conformance}}
  func method4(_: Never) // expected-note {{protocol requires function 'method4' with type '(Never) -> ()'; add a stub for conformance}}
}
do {
  struct Conformer: P7 {} // expected-error {{type 'Conformer' does not conform to protocol 'P7'}}
}

protocol P8 {
  associatedtype A: Sequence where A.Element == Never

  func method1(_: A) // expected-note {{protocol requires function 'method1' with type '(Conformer.A) -> ()' (aka '(Array<Bool>) -> ()'); add a stub for conformance}}
  func method2() -> A.Element // expected-note {{protocol requires function 'method2()' with type '() -> Bool'; add a stub for conformance}}
  func method3<T>(_: T) where T: Sequence, T.Element == A
  // expected-note@-1 {{protocol requires function 'method3' with type '<T> (T) -> ()'; add a stub for conformance}}
  func method4(_: Never) // expected-note {{protocol requires function 'method4' with type '(Never) -> ()'; add a stub for conformance}}
}
do {
  struct Conformer: P8 {
    // expected-error@-1 {{type 'Conformer' does not conform to protocol 'P8'}}
    // expected-error@-2 {{'P8' requires the types 'Bool' and 'Never' be equivalent}}
    // expected-note@-3 {{requirement specified as 'Self.A.Element' == 'Never' [with Self = Conformer]}}
    typealias A = Array<Bool>
  }
}

protocol P9a {
  associatedtype A
}
protocol P9b: P9a where A: Sequence {
  subscript(subscript1 _: A.Element) -> Never { get }
  subscript<T>(subscript2 _: T) -> Never where T: Sequence, T.Element == A.Element { get }
  // expected-note@-1 {{protocol requires subscript with type '<T> (subscript2: T) -> Never'; add a stub for conformance}}

  func method1(_: A) // expected-note {{protocol requires function 'method1' with type '(Conformer.A) -> ()' (aka '(Bool) -> ()'); add a stub for conformance}}
  func method2() -> A.Element
  func method3<T>(_: T) where T: Sequence, T.Element == A
  // expected-note@-1 {{protocol requires function 'method3' with type '<T> (T) -> ()'; add a stub for conformance}}
  func method4(_: Never) // expected-note {{protocol requires function 'method4' with type '(Never) -> ()'; add a stub for conformance}}
}
do {
  struct Conformer: P9b {
    // expected-error@-1 {{type 'Conformer' does not conform to protocol 'P9b'}}
    // expected-error@-2 {{type 'Conformer.A' (aka 'Bool') does not conform to protocol 'Sequence'}}
    typealias A = Bool
  }
}

protocol P10a {
  associatedtype A
}
protocol P10b: P10a where A: Sequence, A.Element == Never {
  func method1(_: A) // expected-note {{protocol requires function 'method1' with type '(Conformer.A) -> ()' (aka '(Array<Bool>) -> ()'); add a stub for conformance}}
  func method2() -> A.Element // expected-note {{protocol requires function 'method2()' with type '() -> Bool'; add a stub for conformance}}
  func method3<T>(_: T) where T: Sequence, T.Element == A
  // expected-note@-1 {{protocol requires function 'method3' with type '<T> (T) -> ()'; add a stub for conformance}}
  func method4(_: Never) // expected-note {{protocol requires function 'method4' with type '(Never) -> ()'; add a stub for conformance}}
}
do {
  struct Conformer: P10b {
    // expected-error@-1 {{type 'Conformer' does not conform to protocol 'P10b'}}
    // expected-error@-2 {{'P10b' requires the types 'Bool' and 'Never' be equivalent}}
    // expected-note@-3 {{requirement specified as 'Self.A.Element' == 'Never' [with Self = Conformer]}}
    typealias A = Array<Bool>
  }
}

protocol P11 {
  associatedtype A: Equatable
  // FIXME: Should not resolve witness for 'method', but Type::subst doesn't care
  // about conditional requirements when querying type witnesses.
  // expected-note@+1 {{protocol requires function 'method()' with type '() -> Conformer.A' (aka '() -> Array<any P11>'); add a stub for conformance}}
  func method() -> A
}
do {
  struct Conformer: P11 {
    // expected-error@-1 {{type 'Conformer' does not conform to protocol 'P11'}}
    // expected-error@-2 {{type 'any P11' does not conform to protocol 'Equatable'}} // FIXME: Crappy diagnostics
    // expected-error@-3 {{'P11' requires that 'any P11' conform to 'Equatable'}}
    // expected-note@-4 {{requirement specified as 'any P11' : 'Equatable'}}
    // expected-note@-5 {{requirement from conditional conformance of 'Conformer.A' (aka 'Array<any P11>') to 'Equatable'}}
    typealias A = Array<any P11>
  }
}

protocol P12 {
  associatedtype A: Sequence where A.Element == Never // expected-note {{protocol requires nested type 'A'; add nested type 'A' for conformance}}
  // FIXME: Should not resolve witness for 'prop', but getInterfaceType() returns
  // '(Self) -> Never' instead of '(Self) -> Self.A.Element', and the invalid
  // type parameter is never found (see 'hasInvalidTypeInConformanceContext').
  // This happens because getInterfaceType() on properties returns contextual
  // types that have been mapped out of context, but mapTypeOutOfContext() does
  // not reconstitute type parameters that were substituted with concrete types.
  // Instead, patterns should be refactored to use interface types, at least if
  // they appear in type contexts.
  //
  // expected-note@+1 {{protocol requires property 'prop' with type '(Conformer) -> Never'; add a stub for conformance}}
  var prop: (Self) -> A.Element { get }
}
do {
  struct Conformer: P12 { // expected-error {{type 'Conformer' does not conform to protocol 'P12'}}
    typealias A = Bool // expected-note {{possibly intended match 'Conformer.A' (aka 'Bool') does not conform to 'Sequence'}}
  }
}

class Class13 {}
protocol P13a {
  associatedtype A
}
protocol P13b: P13a where A: Class13 {}
do {
  struct Conformer: P13b {
    // expected-error@-1 {{type 'Conformer' does not conform to protocol 'P13b'}}
    // expected-error@-2 {{'P13b' requires that 'Conformer.A' (aka 'Array<Bool>') inherit from 'Class13'}}
    // expected-note@-3 {{requirement specified as 'Self.A' : 'Class13' [with Self = Conformer]}}
    typealias A = Array<Bool>
  }
}