Skip to content

Commit 604553f

Browse files
committed
[SR-4347] added more test cases
1 parent 3851145 commit 604553f

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

test/Constraints/array_literal.swift

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ func defaultToAny(i: Int, s: String) {
146146
}
147147

148148
/// Check handling of 'nil'.
149-
func joinWithNil<T>(s: String, a: Any, t: T) {
149+
protocol Proto1 {}
150+
protocol Proto2 {}
151+
struct Nilable: ExpressibleByNilLiteral {
152+
init(nilLiteral: ()) {}
153+
}
154+
func joinWithNil<T>(s: String, a: Any, t: T, m: T.Type, p: Proto1 & Proto2, arr: [Int], opt: Int?, iou: Int!, n: Nilable) {
150155
let a1 = [s, nil]
151156
let _: Int = a1 // expected-error{{value of type '[String?]'}}
152157

@@ -188,6 +193,42 @@ func joinWithNil<T>(s: String, a: Any, t: T) {
188193

189194
let a14 = [nil, t]
190195
let _: Int = a14 // expected-error{{value of type '[T?]'}}
196+
197+
let a15 = [m, nil]
198+
let _: Int = a15 // expected-error{{value of type '[T.Type?]'}}
199+
200+
let a16 = [nil, m]
201+
let _: Int = a16 // expected-error{{value of type '[T.Type?]'}}
202+
203+
let a17 = [p, nil]
204+
let _: Int = a17 // expected-error{{value of type '[(Proto1 & Proto2)?]'}}
205+
206+
let a18 = [nil, p]
207+
let _: Int = a18 // expected-error{{value of type '[(Proto1 & Proto2)?]'}}
208+
209+
let a19 = [arr, nil]
210+
let _: Int = a19 // expected-error{{value of type '[[Int]?]'}}
211+
212+
let a20 = [nil, arr]
213+
let _: Int = a20 // expected-error{{value of type '[[Int]?]'}}
214+
215+
let a21 = [opt, nil]
216+
let _: Int = a21 // expected-error{{value of type '[Int?]'}}
217+
218+
let a22 = [nil, opt]
219+
let _: Int = a22 // expected-error{{value of type '[Int?]'}}
220+
221+
let a23 = [iou, nil]
222+
let _: Int = a23 // expected-error{{value of type '[Int?]'}}
223+
224+
let a24 = [nil, iou]
225+
let _: Int = a24 // expected-error{{value of type '[Int?]'}}
226+
227+
let a25 = [n, nil]
228+
let _: Int = a25 // expected-error{{value of type '[Nilable]'}}
229+
230+
let a26 = [nil, n]
231+
let _: Int = a26 // expected-error{{value of type '[Nilable]'}}
191232
}
192233

193234
struct OptionSetLike : ExpressibleByArrayLiteral {

test/Constraints/optional.swift

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ func testVoidOptional() {
120120
voidOptional(optNoop)
121121
}
122122

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) {
124129
let t1 = b ? s : nil
125130
let _: Double = t1 // expected-error{{value of type 'String?'}}
126131
let t2 = b ? nil : i
@@ -149,6 +154,30 @@ func testTernaryWithNil<T>(b: Bool, s: String, i: Int, a: Any, t: T) {
149154
let _: Double = t13 // expected-error{{value of type 'T?'}}
150155
let t14 = b ? nil : t
151156
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'}}
152181
}
153182

154183
// inference with IUOs

0 commit comments

Comments
 (0)