@@ -120,7 +120,12 @@ func testVoidOptional() {
120
120
voidOptional ( optNoop)
121
121
}
122
122
123
- func testTernaryWithNil< T> ( b: Bool , s: String , i: Int , a: Any , t: T ) {
123
+ protocol Proto1 { }
124
+ protocol Proto2 { }
125
+ struct Nilable : ExpressibleByNilLiteral {
126
+ init ( nilLiteral: ( ) ) { }
127
+ }
128
+ func testTernaryWithNil< T> ( b: Bool , s: String , i: Int , a: Any , t: T , m: T . Type , p: Proto1 & Proto2 , arr: [ Int ] , opt: Int ? , iou: Int ! , n: Nilable ) {
124
129
let t1 = b ? s : nil
125
130
let _: Double = t1 // expected-error{{value of type 'String?'}}
126
131
let t2 = b ? nil : i
@@ -149,6 +154,30 @@ func testTernaryWithNil<T>(b: Bool, s: String, i: Int, a: Any, t: T) {
149
154
let _: Double = t13 // expected-error{{value of type 'T?'}}
150
155
let t14 = b ? nil : t
151
156
let _: Double = t14 // expected-error{{value of type 'T?'}}
157
+ let t15 = b ? m : nil
158
+ let _: Double = t15 // expected-error{{value of type 'T.Type?'}}
159
+ let t16 = b ? nil : m
160
+ let _: Double = t16 // expected-error{{value of type 'T.Type?'}}
161
+ let t17 = b ? p : nil
162
+ let _: Double = t17 // expected-error{{value of type '(Proto1 & Proto2)?'}}
163
+ let t18 = b ? nil : p
164
+ let _: Double = t18 // expected-error{{value of type '(Proto1 & Proto2)?'}}
165
+ let t19 = b ? arr : nil
166
+ let _: Double = t19 // expected-error{{value of type '[Int]?'}}
167
+ let t20 = b ? nil : arr
168
+ let _: Double = t20 // expected-error{{value of type '[Int]?'}}
169
+ let t21 = b ? opt : nil
170
+ let _: Double = t21 // expected-error{{value of type 'Int?'}}
171
+ let t22 = b ? nil : opt
172
+ let _: Double = t22 // expected-error{{value of type 'Int?'}}
173
+ let t23 = b ? iou : nil
174
+ let _: Double = t23 // expected-error{{value of type 'Int?'}}
175
+ let t24 = b ? nil : iou
176
+ let _: Double = t24 // expected-error{{value of type 'Int?'}}
177
+ let t25 = b ? n : nil
178
+ let _: Double = t25 // expected-error{{value of type 'Nilable'}}
179
+ let t26 = b ? nil : n
180
+ let _: Double = t26 // expected-error{{value of type 'Nilable'}}
152
181
}
153
182
154
183
// inference with IUOs
0 commit comments