@@ -50,6 +50,26 @@ CastsTests.test("No overrelease of existential boxes in failed casts") {
50
50
51
51
extension Int : P { }
52
52
53
+ // Test for SR-7664: Inconsistent optional casting behaviour with generics
54
+ // Runtime failed to unwrap multiple levels of Optional when casting.
55
+ CastsTests . test ( " Multi-level optionals can be casted " ) {
56
+ func testSuccess< From, To> ( _ x: From , from: From . Type , to: To . Type ) {
57
+ expectNotNil ( x as? To )
58
+ }
59
+ func testFailure< From, To> ( _ x: From , from: From . Type , to: To . Type ) {
60
+ expectNil ( x as? To )
61
+ }
62
+ testSuccess ( 42 , from: Int ? . self, to: Int . self)
63
+ testSuccess ( 42 , from: Int?? . self , to: Int . self)
64
+ testSuccess ( 42 , from: Int??? . self , to: Int . self)
65
+ testSuccess ( 42 , from: Int??? . self , to: Int ? . self)
66
+ testSuccess ( 42 , from: Int??? . self , to: Int?? . self )
67
+ testSuccess ( 42 , from: Int??? . self , to: Int??? . self )
68
+ testFailure ( 42 , from: Int ? . self, to: String . self)
69
+ testFailure ( 42 , from: Int?? . self , to: String . self)
70
+ testFailure ( 42 , from: Int??? . self , to: String . self)
71
+ }
72
+
53
73
#if _runtime(_ObjC)
54
74
extension CFBitVector : P {
55
75
static func makeImmutable( from values: Array < UInt8 > ) -> CFBitVector {
0 commit comments