Skip to content

Commit 8207abd

Browse files
[tests] Adding regression tests for SR-7187 and SR-6192
1 parent efc46bd commit 8207abd

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

test/Constraints/casts.swift

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func test_tuple_casts_no_warn() {
232232
_ = arr as! [(Foo, Foo)] // Ok
233233
_ = tup as! (Foo, Foo) // Ok
234234

235-
_ = arr as! [(Foo, Foo, Foo)] // expected-warning {{cast from '[(Any, Any)]' to unrelated type '[(Foo, Foo, Foo)]' always fails}}
235+
_ = arr as! [(Foo, Foo, Foo)] // Ok
236236
_ = tup as! (Foo, Foo, Foo) // expected-warning {{cast from '(Any, Any)' to unrelated type '(Foo, Foo, Foo)' always fails}}
237237

238238
_ = arr as! [(a: Foo, Foo)] // Ok
@@ -422,6 +422,33 @@ func tests_SR13088_false_positive_always_fail_casts() {
422422
break
423423
}
424424
}
425+
426+
// SR-7187
427+
let a: [Any] = [String?.some("hello") as Any, String?.none as Any]
428+
let b: [AnyObject] = [String?.some("hello") as AnyObject, String?.none as AnyObject]
429+
430+
_ = a is [String?] // Ok
431+
_ = a as? [String?] as Any // OK
432+
_ = b is [String?] // Ok
433+
_ = b as? [String?] as AnyObject // OK
434+
435+
// SR-6192
436+
let items = [String]()
437+
let dict = [String: Any]()
438+
let set = Set<String>()
439+
440+
_ = items is [Int] // Ok
441+
_ = items as? [Int] as Any // Ok
442+
_ = items as! [Int] // Ok
443+
444+
_ = dict is [Int: Any] // Ok
445+
_ = dict as? [Int: Any] as Any // Ok
446+
_ = dict as! [Int: Any] as Any // Ok
447+
448+
_ = set is Set<Int> // Ok
449+
_ = set as? Set<Int> as Any // Ok
450+
_ = set as! Set<Int> // Ok
451+
425452
}
426453

427454
// Protocol composition

test/expr/cast/as_coerce.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ Double(1) as Double as String // expected-error{{cannot convert value of type 'D
9292
(1, 1.0, "a", [1, 23]) as (Int, Double, String, [String])
9393
// expected-error@-1 2 {{cannot convert value of type 'Int' to expected element type 'String'}}
9494

95-
_ = [1] as! [String] // expected-warning{{cast from '[Int]' to unrelated type '[String]' always fails}}
96-
_ = [(1, (1, 1))] as! [(Int, (String, Int))] // expected-warning{{cast from '[(Int, (Int, Int))]' to unrelated type '[(Int, (String, Int))]' always fails}}
95+
_ = [1] as! [String] // OK
96+
_ = [(1, (1, 1))] as! [(Int, (String, Int))] // OK
9797

9898
// <rdar://problem/19495253> Incorrect diagnostic for explicitly casting to the same type
9999
_ = "hello" as! String // expected-warning{{forced cast of 'String' to same type has no effect}} {{13-24=}}

test/expr/cast/dictionary_downcast.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dictCC as Dictionary<U, U> // expected-error{{cannot convert value of type '[C :
4343
// expected-note@-2 {{arguments to generic parameter 'Value' ('C' and 'U') are expected to be equal}}
4444

4545
// Test dictionary conditional downcasts to unrelated types
46-
if let _ = dictCC as? Dictionary<D, U> { } // expected-warning{{cast from '[C : C]' to unrelated type 'Dictionary<D, U>' always fails}}
47-
if let _ = dictCC as? Dictionary<U, D> { } // expected-warning{{cast from '[C : C]' to unrelated type 'Dictionary<U, D>' always fails}}
48-
if let _ = dictCC as? Dictionary<U, U> { } // expected-warning{{cast from '[C : C]' to unrelated type 'Dictionary<U, U>' always fails}}
46+
if let _ = dictCC as? Dictionary<D, U> { } // Ok
47+
if let _ = dictCC as? Dictionary<U, D> { } // Ok
48+
if let _ = dictCC as? Dictionary<U, U> { } // Ok
4949

test/expr/cast/set_bridge.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func testConditionalDowncastBridge() {
9494
if let s = setB as? Set<Root> { _ = s } // expected-warning{{conditional cast from 'Set<BridgedToObjC>' to 'Set<Root>' always succeeds}}
9595
if let s = setB as? Set<ObjC> { _ = s } // expected-warning{{conditional cast from 'Set<BridgedToObjC>' to 'Set<ObjC>' always succeeds}}
9696
if let s = setB as? Set<DerivesObjC> { _ = s }
97-
if let s = setB as? Set<Unrelated> { _ = s } // expected-warning {{cast from 'Set<BridgedToObjC>' to unrelated type 'Set<Unrelated>' always fails}}
97+
if let s = setB as? Set<Unrelated> { _ = s } // OK
9898

9999
_ = setR
100100
_ = setO

test/expr/cast/set_downcast.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ setD = setC as! Set<D>
3030
if let _ = setC as? Set<D> { }
3131

3232
// Test set downcasts to unrelated types.
33-
_ = setC as! Set<U> // expected-warning{{cast from 'Set<C>' to unrelated type 'Set<U>' always fails}}
33+
_ = setC as! Set<U> // Ok
3434

35-
// Test set conditional downcasts to unrelated types
36-
if let _ = setC as? Set<U> { } // expected-warning{{cast from 'Set<C>' to unrelated type 'Set<U>' always fails}}
35+
// Test set conditional downcasts to unrelated types.
36+
if let _ = setC as? Set<U> { } // Ok

0 commit comments

Comments
 (0)