@@ -174,95 +174,79 @@ func thirteen() {
174
174
}
175
175
}
176
176
177
- // SR 6400
178
-
179
- enum SR_6400_E : Error {
180
- case castError
181
- }
177
+ // https://github.com/apple/swift/issues/48950
178
+ protocol ClassProto : AnyObject { }
179
+ do {
180
+ enum E : Error {
181
+ case castError
182
+ }
182
183
183
- struct SR_6400_S_1 { }
184
- struct SR_6400_S_2 : Error { }
184
+ do {
185
+ struct S1 { }
186
+ struct S2 : Error { }
185
187
186
- protocol SR_6400_FakeApplicationDelegate : AnyObject { }
187
- class SR_6400_FakeViewController { }
188
+ do {
189
+ throw E . castError
190
+ } catch is S1 { } // expected-warning {{cast from 'any Error' to unrelated type 'S1' always fails}}
188
191
189
- func sr_6400( ) throws {
190
- do {
191
- throw SR_6400_E . castError
192
- } catch is SR_6400_S_1 { // expected-warning {{cast from 'any Error' to unrelated type 'SR_6400_S_1' always fails}}
193
- print ( " Caught error " )
194
- }
195
-
196
- do {
197
- throw SR_6400_E . castError
198
- } catch is SR_6400_S_2 {
199
- print ( " Caught error " ) // Ok
192
+ do {
193
+ throw E . castError
194
+ } catch is S2 { } // Ok
200
195
}
201
- }
202
196
203
- func sr_6400_1< T> ( error: Error , as type: T . Type ) -> Bool {
204
- return ( error as? T ) != nil // Ok
205
- }
206
-
207
- func sr_6400_2( error: Error ) {
208
- _ = error as? ( SR_6400_FakeViewController & Error ) // Ok
209
- }
210
- func sr_6400_3( error: Error ) {
211
- _ = error as? ( Error & SR_6400_FakeApplicationDelegate ) // Ok
212
- }
197
+ do {
198
+ class C1 { }
199
+ class C2 : ClassProto & Error { }
213
200
214
- class SR_6400_A { }
215
- class SR_6400_B : SR_6400_FakeApplicationDelegate & Error { }
201
+ do {
202
+ throw E . castError
203
+ } catch let error as C1 { // Okay
204
+ print ( error)
205
+ } catch { }
216
206
217
- func sr_6400_4( ) {
218
- do {
219
- throw SR_6400_E . castError
220
- } catch let error as SR_6400_A { // Okay
221
- print ( error)
222
- } catch {
223
- print ( " Bar " )
207
+ do {
208
+ throw E . castError
209
+ } catch let error as C2 { // Okay
210
+ print ( error)
211
+ } catch { }
212
+
213
+ let err : Error
214
+ _ = err as? ( C1 & Error ) // Ok
215
+ _ = err as? ( Error & ClassProto ) // Ok
224
216
}
225
-
226
- do {
227
- throw SR_6400_E . castError
228
- } catch let error as SR_6400_B { // Okay
229
- print ( error)
230
- } catch {
231
- print ( " Bar " )
217
+
218
+ func f< T> ( error: Error , as type: T . Type ) -> Bool {
219
+ return ( error as? T ) != nil // Ok
232
220
}
233
221
}
234
222
235
- // SR-11402
223
+ // https://github.com/apple/swift/issues/53803
224
+ protocol P { }
225
+ do {
226
+ class Super { }
227
+ class Sub : Super , P { }
228
+ final class Final { }
236
229
237
- protocol SR_11402_P { }
238
- class SR_11402_Superclass { }
239
- class SR_11402_Subclass : SR_11402_Superclass , SR_11402_P { }
230
+ let x : any P
240
231
241
- func sr_11402_func1( _ x: SR_11402_P ) {
242
- if let y = x as? SR_11402_Superclass { // Okay
243
- print ( y)
244
- }
245
- }
246
-
247
- final class SR_11402_Final { }
232
+ if let _ = x as? Super { } // Okay
248
233
249
- func sr_11402_func2( _ x: SR_11402_P ) {
250
- if let y = x as? SR_11402_Final { // expected-warning {{cast from 'any SR_11402_P' to unrelated type 'SR_11402_Final' always fails}}
251
- print ( y)
252
- }
234
+ if let _ = x as? Final { } // expected-warning {{cast from 'any P' to unrelated type 'Final' always fails}}
253
235
}
254
236
255
- // https://bugs.swift.org/browse/SR-13654
237
+ // https://github.com/apple/swift/issues/56091
238
+ do {
239
+ func f( ) throws -> String { }
256
240
257
- func sr_13654_func( ) throws -> String { }
241
+ func invalid_interpolation( ) {
242
+ _ = try " \( f ( ) ) " // expected-error {{errors thrown from here are not handled}}
243
+ _ = " \( try f ( ) ) " // expected-error {{errors thrown from here are not handled}}
244
+ }
258
245
259
- func sr_13654_invalid_interpolation( ) {
260
- _ = try " \( sr_13654_func ( ) ) " // expected-error {{errors thrown from here are not handled}}
261
- _ = " \( try sr_13654_func ( ) ) " // expected-error {{errors thrown from here are not handled}}
262
- }
263
- func sr_13654_valid_interpolation( ) throws {
264
- _ = try " \( sr_13654_func ( ) ) "
265
- _ = " \( try sr_13654_func ( ) ) "
246
+ func valid_interpolation( ) throws {
247
+ _ = try " \( f ( ) ) "
248
+ _ = " \( try f ( ) ) "
249
+ }
266
250
}
267
251
268
252
// rdar://problem/72748150
0 commit comments