@@ -235,8 +235,8 @@ func test_tuple_casts_no_warn() {
235
235
_ = arr as! [ ( Foo , Foo , Foo ) ] // expected-warning {{cast from '[(Any, Any)]' to unrelated type '[(Foo, Foo, Foo)]' always fails}}
236
236
_ = tup as! ( Foo , Foo , Foo ) // expected-warning {{cast from '(Any, Any)' to unrelated type '(Foo, Foo, Foo)' always fails}}
237
237
238
- _ = arr as! [ ( a: Foo , Foo ) ] // expected-warning {{cast from '[(Any, Any)]' to unrelated type '[(a: Foo, Foo)]' always fails}}
239
- _ = tup as! ( a: Foo , Foo ) // expected-warning {{cast from '(Any, Any)' to unrelated type '(a: Foo, Foo)' always fails}}
238
+ _ = arr as! [ ( a: Foo , Foo ) ] // Ok
239
+ _ = tup as! ( a: Foo , Foo ) // Ok
240
240
}
241
241
242
242
infix operator ^^^
@@ -335,3 +335,72 @@ func test_compatibility_coercions(_ arr: [Int], _ optArr: [Int]?, _ dict: [Strin
335
335
// The array can also be inferred to be [Any].
336
336
_ = ( [ ] ?? [ ] ) as Array // expected-warning {{left side of nil coalescing operator '??' has non-optional type '[Any]', so the right side is never used}}
337
337
}
338
+
339
+ // SR-13088
340
+ protocol JSON { }
341
+ protocol JSONLeaf : JSON { }
342
+ extension Int : JSONLeaf { }
343
+ extension Array : JSON where Element: JSON { }
344
+
345
+ protocol SR13035Error : Error { }
346
+ struct ChildError : SR13035Error { }
347
+
348
+ protocol AnyC {
349
+ func foo( )
350
+ }
351
+
352
+ protocol AnyEvent { }
353
+
354
+ protocol A {
355
+ associatedtype C : AnyC
356
+ }
357
+
358
+ protocol EventA : A {
359
+ associatedtype Event
360
+ }
361
+
362
+ typealias Container < Namespace>
363
+ = ( event: Namespace . Event , c: Namespace . C ) where Namespace: EventA
364
+
365
+ enum ConcreteA : EventA {
366
+ struct C : AnyC {
367
+ func foo( ) { }
368
+ }
369
+
370
+ enum Event : AnyEvent {
371
+ case test
372
+ }
373
+ }
374
+
375
+ func tests_SR13088_false_positive_always_fail_casts( ) {
376
+ // SR-13081
377
+ let x : JSON = [ 4 ] // [4]
378
+ _ = x as? [ Any ] // Ok
379
+
380
+ // SR-7187
381
+ let a : [ Any ] = [ String ? . some ( " hello " ) as Any , String ? . none as Any ]
382
+
383
+ _ = a is [ String ? ] // Ok
384
+ _ = a as? [ String ? ] // Ok
385
+
386
+ // SR-13035
387
+ func SR13035< SomeError: SR13035Error > ( _ mockResult: Result < String , ChildError > , _: Result < String , SomeError > ) {
388
+ let _ = mockResult as? Result < String , SomeError > // Ok
389
+ }
390
+
391
+ // SR-11434 and SR-12321
392
+ func encodable( _ value: Encodable ) {
393
+ _ = value as! [ String : Encodable ] // Ok
394
+ _ = value as? [ String : Encodable ] // Ok
395
+ }
396
+
397
+ // SR-13025
398
+ func coordinate( _ event: AnyEvent , from c: AnyC ) {
399
+ switch ( event, c) {
400
+ case let container as Container < ConcreteA > : // OK
401
+ container. c. foo ( )
402
+ default :
403
+ break
404
+ }
405
+ }
406
+ }
0 commit comments