|
2 | 2 |
|
3 | 3 | let ok = "A" as Character // OK |
4 | 4 | let succeed = "A" as? String // expected-warning {{always succeeds}} |
5 | | -let bad = "A" as? Character // expected-warning {{conditional downcast from literal to 'Character' always fails; consider using 'as' coercion}} {{none}} |
| 5 | +let force = "A" as! String // expected-warning {{forced cast of 'String' to same type has no effect}} |
| 6 | +let bad = "A" as? Character // expected-warning {{cast from literal of inferred type 'String' to unrelated type 'Character' always fails; consider using 'as' coercion}} {{none}} |
6 | 7 | let bad2 = "Aa" as? Character // expected-warning {{cast from 'String' to unrelated type 'Character' always fails}} |
| 8 | +let badForce = "Aa" as! Character // expected-warning {{cast from 'String' to unrelated type 'Character' always fails}} |
7 | 9 | let bad1 = 1 as? Character // expected-warning {{cast from 'Int' to unrelated type 'Character' always fails}} |
| 10 | +let bad1Force = 1 as! Character // expected-warning {{cast from 'Int' to unrelated type 'Character' always fails}} |
8 | 11 |
|
9 | 12 | let okInt = 1 as Int // OK |
| 13 | +let IntForce = 1 as! Int // expected-warning {{forced cast of 'Int' to same type has no effect}} |
10 | 14 | let badInt = 1 as? Int // expected-warning {{always succeeds}} |
11 | 15 | let badInt1 = 1.0 as? Int // expected-warning {{cast from 'Double' to unrelated type 'Int' always fails}} |
12 | | -let badInt2 = 1 as? Double // expected-warning {{conditional downcast from literal to 'Double' always fails; consider using 'as' coercion}} {{none}} |
| 16 | +let badInt2 = 1 as? Double // expected-warning {{cast from literal of inferred type 'Int' to unrelated type 'Double' always fails; consider using 'as' coercion}} {{none}} |
| 17 | +let badInt3 = 1 as! Double // expected-warning {{cast from literal of inferred type 'Int' to unrelated type 'Double' always fails; consider using 'as' coercion}} |
| 18 | +let badInt4 = 1.0 as! Int // expected-warning {{cast from 'Double' to unrelated type 'Int' always fails}} |
13 | 19 |
|
14 | 20 | let okUInt = 1 as UInt // OK |
15 | | -let badUInt = 1 as? UInt // expected-warning {{conditional downcast from literal to 'UInt' always fails; consider using 'as' coercion}} {{none}} |
| 21 | +let badUInt = 1 as? UInt // expected-warning {{cast from literal of inferred type 'Int' to unrelated type 'UInt' always fails; consider using 'as' coercion}} {{none}} |
16 | 22 | let badUInt1 = 1.0 as? UInt // expected-warning {{cast from 'Double' to unrelated type 'UInt' always fails}} |
| 23 | +let badUInt2 = 1.0 as! UInt // expected-warning {{cast from 'Double' to unrelated type 'UInt' always fails}} |
| 24 | +let badUInt3 = 1 as! UInt // expected-warning {{cast from literal of inferred type 'Int' to unrelated type 'UInt' always fails; consider using 'as' coercion}} |
17 | 25 |
|
18 | 26 | // Custom protocol adoption |
19 | 27 | struct S: ExpressibleByStringLiteral { |
20 | 28 | typealias StringLiteralType = String |
21 | 29 | init(stringLiteral value: Self.StringLiteralType) {} |
22 | 30 | } |
23 | 31 |
|
24 | | -let a = "A" as? S // expected-warning {{conditional downcast from literal to 'S' always fails; consider using 'as' coercion}} {{none}} |
| 32 | +let a = "A" as? S // expected-warning {{cast from literal of inferred type 'String' to unrelated type 'S' always fails; consider using 'as' coercion}} {{none}} |
| 33 | +let a1 = "A" as! S // expected-warning {{cast from literal of inferred type 'String' to unrelated type 'S' always fails; consider using 'as' coercion}} |
0 commit comments