|
| 1 | +// RUN: %target-typecheck-verify-swift |
| 2 | + |
| 3 | +let x: _ = 0 |
| 4 | +let dict1: [_: Int] = ["hi": 0] |
| 5 | +let dict2: [Character: _] = ["h": 0] |
| 6 | + |
| 7 | +let arr = [_](repeating: "hi", count: 3) |
| 8 | + |
| 9 | +func foo(_ arr: [_] = [0]) {} // expected-error {{placeholder type not allowed here}} |
| 10 | + |
| 11 | +let foo = _.foo // expected-error {{could not infer type for placeholder}} |
| 12 | +let zero: _ = .zero // expected-error {{cannot infer contextual base in reference to member 'zero'}} |
| 13 | + |
| 14 | +struct S<T> { |
| 15 | + var x: T |
| 16 | +} |
| 17 | + |
| 18 | +var s1: S<_> = .init(x: 0) |
| 19 | +var s2 = S<_>(x: 0) |
| 20 | + |
| 21 | +let losslessStringConverter = Double.init as (String) -> _? |
| 22 | + |
| 23 | +let optInt: _? = 0 |
| 24 | +let implicitOptInt: _! = 0 |
| 25 | + |
| 26 | +let func1: (_) -> Double = { (x: Int) in 0.0 } |
| 27 | +let func2: (Int) -> _ = { x in 0.0 } |
| 28 | +let func3: (_) -> _ = { (x: Int) in 0.0 } |
| 29 | +let func4: (_, String) -> _ = { (x: Int, y: String) in 0.0 } |
| 30 | +let func5: (_, String) -> _ = { (x: Int, y: Double) in 0.0 } // expected-error {{cannot convert value of type '(Int, Double) -> _' to specified type '(_, String) -> _'}} |
| 31 | + |
| 32 | +let type: _.Type = Int.self |
| 33 | +let type2: Int.Type.Type = _.Type.self |
| 34 | + |
| 35 | +struct MyType1<T, U> { |
| 36 | + init(t: T, mt2: MyType2<T>) where U == MyType2<T> {} |
| 37 | +} |
| 38 | + |
| 39 | +struct MyType2<T> { |
| 40 | + init(t: T) {} |
| 41 | +} |
| 42 | + |
| 43 | +let _: MyType2<_> = .init(t: "c" as Character) |
| 44 | +let _: MyType1<_, MyType2<_>> = .init(t: "s" as Character, mt2: .init(t: "c" as Character)) |
| 45 | + |
| 46 | +func dictionary<K, V>(ofType: [K: V].Type) -> [K: V] { [:] } |
| 47 | + |
| 48 | +let _: [String: _] = dictionary(ofType: [_: Int].self) |
| 49 | +let _: [_: _] = dictionary(ofType: [String: Int].self) |
| 50 | +let _: [String: Int] = dictionary(ofType: _.self) |
| 51 | + |
0 commit comments