You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/decl/var/usage.swift
+44-2Lines changed: 44 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -330,8 +330,44 @@ func test(_ a : Int?, b : Any) {
330
330
iflet x = b as?Int{ // expected-warning {{value 'x' was defined but never used; consider replacing with boolean test}} {{6-14=}} {{16-19=is}}
331
331
}
332
332
333
-
// SR-1112
333
+
// SR-14646. Special case, turn this into an 'is' test with optional value.
334
+
letbb:Any?=3
335
+
iflet bbb = bb as?Int{} // expected-warning {{value 'bbb' was defined but never used; consider replacing with boolean test}} {{6-16=}} {{19-22=is}}
336
+
iflet bbb =(bb)as?Int{} // expected-warning {{value 'bbb' was defined but never used; consider replacing with boolean test}} {{6-16=}} {{21-24=is}}
337
+
338
+
func aa()->Any?{return1}
339
+
iflet aaa =aa()as?Int{} // expected-warning {{value 'aaa' was defined but never used; consider replacing with boolean test}} {{6-16=}} {{21-24=is}}
340
+
iflet aaa =(aa())as?Int{} // expected-warning {{value 'aaa' was defined but never used; consider replacing with boolean test}} {{6-16=}} {{23-26=is}}
341
+
342
+
func bb()->Any{return1}
343
+
iflet aaa =aa()as?Int{} // expected-warning {{value 'aaa' was defined but never used; consider replacing with boolean test}} {{6-16=}} {{21-24=is}}
344
+
iflet aaa =(aa())as?Int{} // expected-warning {{value 'aaa' was defined but never used; consider replacing with boolean test}} {{6-16=}} {{23-26=is}}
334
345
346
+
347
+
func throwingAA()throws->Any?{return1}
348
+
do{
349
+
iflet aaa =try!throwingAA()as?Int{} // expected-warning {{value 'aaa' was defined but never used; consider replacing with boolean test}} {{8-18=}} {{36-39=is}}
350
+
iflet aaa =(try!throwingAA())as?Int{} // expected-warning {{value 'aaa' was defined but never used; consider replacing with boolean test}} {{8-18=}} {{38-41=is}}
351
+
iflet aaa =trythrowingAA()as?Int{} // expected-warning {{value 'aaa' was defined but never used; consider replacing with boolean test}} {{8-18=}} {{35-38=is}}
352
+
iflet aaa =(trythrowingAA())as?Int{} // expected-warning {{value 'aaa' was defined but never used; consider replacing with boolean test}} {{8-18=}} {{37-40=is}}
353
+
}catch{}
354
+
iflet aaa =try?throwingAA()as?Int{} // expected-warning {{value 'aaa' was defined but never used; consider replacing with boolean test}} {{6-16=(}} {{41-41=) != nil}}
355
+
iflet aaa =(try?throwingAA())as?Int{} // expected-warning {{value 'aaa' was defined but never used; consider replacing with boolean test}} {{6-16=}} {{36-39=is}}
356
+
357
+
func throwingBB()throws->Any{return1}
358
+
do{
359
+
iflet bbb =try!throwingBB()as?Int{} // expected-warning {{value 'bbb' was defined but never used; consider replacing with boolean test}} {{8-18=}} {{36-39=is}}
360
+
iflet bbb =(try!throwingBB())as?Int{} // expected-warning {{value 'bbb' was defined but never used; consider replacing with boolean test}} {{8-18=}} {{38-41=is}}
361
+
iflet bbb =trythrowingBB()as?Int{} // expected-warning {{value 'bbb' was defined but never used; consider replacing with boolean test}} {{8-18=}} {{35-38=is}}
362
+
iflet bbb =(trythrowingBB())as?Int{} // expected-warning {{value 'bbb' was defined but never used; consider replacing with boolean test}} {{8-18=}} {{37-40=is}}
363
+
}catch{}
364
+
iflet bbb =try?throwingBB()as?Int{} // expected-warning {{value 'bbb' was defined but never used; consider replacing with boolean test}} {{6-16=(}} {{41-41=) != nil}}
365
+
iflet bbb =(try?throwingBB())as?Int{} // expected-warning {{value 'bbb' was defined but never used; consider replacing with boolean test}} {{6-16=}} {{36-39=is}}
366
+
367
+
letcc:(Any?,Any)=(1,2)
368
+
iflet(cc1, cc2)= cc as?(Int,Int){} // expected-warning {{immutable value 'cc1' was never used; consider replacing with '_' or removing it}} expected-warning {{immutable value 'cc2' was never used; consider replacing with '_' or removing it}}
@@ -356,7 +392,7 @@ let optionalString: String? = "check"
356
392
iflet string = optionalString {} // expected-warning {{value 'string' was defined but never used; consider replacing with boolean test}} {{4-17=}} {{31-31= != nil}}
357
393
358
394
letoptionalAny:Any?="check"
359
-
iflet string = optionalAny as?String{} // expected-warning {{value 'string' was defined but never used; consider replacing with boolean test}} {{4-17=(}} {{39-39=) != nil}}
395
+
iflet string = optionalAny as?String{} // expected-warning {{value 'string' was defined but never used; consider replacing with boolean test}} {{4-17=}} {{29-32=is}}
360
396
361
397
// Due to the complexities of global variable tracing, these will not generate warnings
iflet bar = foo as?Foo{return42} // expected-warning {{value 'bar' was defined but never used; consider replacing with boolean test}} {{6-16=}} {{20-23=is}}
0 commit comments