Skip to content

Commit 0c57aeb

Browse files
author
Brian King
committed
Fix unit tests
1 parent d835167 commit 0c57aeb

File tree

11 files changed

+68
-66
lines changed

11 files changed

+68
-66
lines changed

test/Compatibility/tuple_arguments.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ do {
5353
}
5454

5555
do {
56-
var a = 3
57-
var b = 4
58-
var c = (3)
59-
var d = (a, b)
56+
var a = 3 // expected-warning {{variable 'a' was never mutated; consider changing to 'let' constant}}
57+
var b = 4 // expected-warning {{variable 'b' was never mutated; consider changing to 'let' constant}}
58+
var c = (3) // expected-warning {{variable 'c' was never mutated; consider changing to 'let' constant}}
59+
var d = (a, b) // expected-warning {{variable 'd' was never mutated; consider changing to 'let' constant}}
6060

6161
concrete(a)
6262
concrete((a))
@@ -535,9 +535,9 @@ do {
535535
}
536536

537537
do {
538-
var a = 3
539-
var b = 4
540-
var c = (a, b)
538+
var a = 3 // expected-warning {{variable 'a' was never mutated; consider changing to 'let' constant}}
539+
var b = 4 // expected-warning {{variable 'b' was never mutated; consider changing to 'let' constant}}
540+
var c = (a, b) // expected-warning {{variable 'c' was never mutated; consider changing to 'let' constant}}
541541

542542
_ = InitTwo(a, b)
543543
_ = InitTwo((a, b)) // expected-error {{missing argument for parameter #2 in call}}
@@ -583,9 +583,9 @@ do {
583583
}
584584

585585
do {
586-
var a = 3
587-
var b = 4
588-
var d = (a, b)
586+
var a = 3 // expected-warning {{variable 'a' was never mutated; consider changing to 'let' constant}}
587+
var b = 4 // expected-warning {{variable 'b' was never mutated; consider changing to 'let' constant}}
588+
var d = (a, b) // expected-warning {{variable 'd' was never mutated; consider changing to 'let' constant}}
589589

590590
var s1 = SubscriptTwo()
591591
_ = s1[a, b]
@@ -952,9 +952,9 @@ do {
952952
}
953953

954954
do {
955-
var a = 3
956-
var b = 4
957-
var c = (a, b)
955+
var a = 3 // expected-warning {{variable 'a' was never mutated; consider changing to 'let' constant}}
956+
var b = 4 // expected-warning {{variable 'b' was never mutated; consider changing to 'let' constant}}
957+
var c = (a, b) // expected-warning {{variable 'c' was never mutated; consider changing to 'let' constant}}
958958

959959
// _ = GenericInit<(Int, Int)>(a, b) // Crashes in Swift 3
960960
_ = GenericInit<(Int, Int)>((a, b)) // expected-error {{expression type 'GenericInit<(Int, Int)>' is ambiguous without more context}}
@@ -1017,9 +1017,9 @@ do {
10171017
}
10181018

10191019
do {
1020-
var a = 3.0
1021-
var b = 4.0
1022-
var d = (a, b)
1020+
var a = 3.0 // expected-warning {{variable 'a' was never mutated; consider changing to 'let' constant}}
1021+
var b = 4.0 // expected-warning {{variable 'b' was never mutated; consider changing to 'let' constant}}
1022+
var d = (a, b) // expected-warning {{variable 'd' was never mutated; consider changing to 'let' constant}}
10231023

10241024
var s1 = GenericSubscript<(Double, Double)>()
10251025
_ = s1[a, b]

test/Constraints/tuple_arguments.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ do {
3737
}
3838

3939
do {
40-
var a = 3
41-
var b = 4
42-
var c = (3)
43-
var d = (a, b)
40+
var a = 3 // expected-warning {{variable 'a' was never mutated; consider changing to 'let' constant}}
41+
var b = 4 // expected-warning {{variable 'b' was never mutated; consider changing to 'let' constant}}
42+
var c = (3) // expected-warning {{variable 'c' was never mutated; consider changing to 'let' constant}}
43+
var d = (a, b) // expected-warning {{variable 'd' was never mutated; consider changing to 'let' constant}}
4444

4545
concrete(a)
4646
concrete((a))
@@ -520,9 +520,9 @@ do {
520520
}
521521

522522
do {
523-
var a = 3
524-
var b = 4
525-
var c = (a, b)
523+
var a = 3 // expected-warning {{variable 'a' was never mutated; consider changing to 'let' constant}}
524+
var b = 4 // expected-warning {{variable 'b' was never mutated; consider changing to 'let' constant}}
525+
var c = (a, b) // expected-warning {{variable 'c' was never mutated; consider changing to 'let' constant}}
526526

527527
_ = InitTwo(a, b)
528528
_ = InitTwo((a, b)) // expected-error {{missing argument for parameter #2 in call}}
@@ -568,9 +568,9 @@ do {
568568
}
569569

570570
do {
571-
var a = 3
572-
var b = 4
573-
var d = (a, b)
571+
var a = 3 // expected-warning {{variable 'a' was never mutated; consider changing to 'let' constant}}
572+
var b = 4 // expected-warning {{variable 'b' was never mutated; consider changing to 'let' constant}}
573+
var d = (a, b) // expected-warning {{variable 'd' was never mutated; consider changing to 'let' constant}}
574574

575575
var s1 = SubscriptTwo()
576576
_ = s1[a, b]
@@ -937,9 +937,9 @@ do {
937937
}
938938

939939
do {
940-
var a = 3
941-
var b = 4
942-
var c = (a, b)
940+
var a = 3 // expected-warning {{variable 'a' was never mutated; consider changing to 'let' constant}}
941+
var b = 4 // expected-warning {{variable 'b' was never mutated; consider changing to 'let' constant}}
942+
var c = (a, b) // expected-warning {{variable 'c' was never mutated; consider changing to 'let' constant}}
943943

944944
_ = GenericInit<(Int, Int)>(a, b) // expected-error {{extra argument in call}}
945945
_ = GenericInit<(Int, Int)>((a, b))
@@ -1002,9 +1002,9 @@ do {
10021002
}
10031003

10041004
do {
1005-
var a = 3.0
1006-
var b = 4.0
1007-
var d = (a, b)
1005+
var a = 3.0 // expected-warning {{variable 'a' was never mutated; consider changing to 'let' constant}}
1006+
var b = 4.0 // expected-warning {{variable 'b' was never mutated; consider changing to 'let' constant}}
1007+
var d = (a, b) // expected-warning {{variable 'd' was never mutated; consider changing to 'let' constant}}
10081008

10091009
var s1 = GenericSubscript<(Double, Double)>()
10101010
_ = s1[a, b] // expected-error {{extra argument in call}}

test/Parse/availability_query.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ if 1 != 2, #available(iOS 8.0, *) {}
9797

9898
// Pattern then #available(iOS 8.0, *) {
9999
if case 42 = 42, #available(iOS 8.0, *) {}
100-
if let x = Optional(42), #available(iOS 8.0, *) {}
100+
if let _ = Optional(42), #available(iOS 8.0, *) {}
101101

102102
// Allow "macOS" as well.
103103
if #available(macOS 10.51, *) {

test/Parse/matching_patterns.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ case 1 + (_): // expected-error{{'_' can only appear in a pattern or on the left
4747
}
4848

4949
switch (x,x) {
50-
case (var a, var a): // expected-error {{definition conflicts with previous value}} expected-note {{previous definition of 'a' is here}}
50+
case (var a, var a): // expected-error {{definition conflicts with previous value}} expected-note {{previous definition of 'a' is here}} expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}} expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
5151
fallthrough
5252
case _:
5353
()
5454
}
5555

56-
5756
var e : Any = 0
5857

5958
switch e {

test/Parse/switch.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,28 +197,28 @@ default:
197197
var t = (1, 2)
198198

199199
switch t {
200-
case (var a, 2), (1, _): // expected-error {{'a' must be bound in every pattern}}
200+
case (var a, 2), (1, _): // expected-error {{'a' must be bound in every pattern}} expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
201201
()
202202

203203
case (_, 2), (var a, _): // expected-error {{'a' must be bound in every pattern}}
204204
()
205205

206-
case (var a, 2), (1, var b): // expected-error {{'a' must be bound in every pattern}} expected-error {{'b' must be bound in every pattern}}
206+
case (var a, 2), (1, var b): // expected-error {{'a' must be bound in every pattern}} expected-error {{'b' must be bound in every pattern}} expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
207207
()
208208

209-
case (var a, 2): // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{17-17= break}}
209+
case (var a, 2): // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{17-17= break}} expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
210210
case (1, _):
211211
()
212212

213213
case (_, 2): // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{13-13= break}}
214-
case (1, var a):
214+
case (1, var a): // expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
215215
()
216216

217-
case (var a, 2): // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{17-17= break}}
218-
case (1, var b):
217+
case (var a, 2): // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{17-17= break}} expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
218+
case (1, var b): // expected-warning {{variable 'b' was never used; consider replacing with '_' or removing it}}
219219
()
220220

221-
case (1, let b): // let bindings
221+
case (1, let b): // let bindings expected-warning {{immutable value 'b' was never used; consider replacing with '_' or removing it}}
222222
()
223223

224224
case (_, 2), (let a, _): // expected-error {{'a' must be bound in every pattern}}
@@ -228,10 +228,10 @@ case (_, 2), (let a, _): // expected-error {{'a' must be bound in every pattern}
228228
case (_, 2), (1, _):
229229
()
230230

231-
case (_, var a), (_, var a):
231+
case (_, var a), (_, var a): // expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
232232
()
233233

234-
case (var a, var b), (var b, var a):
234+
case (var a, var b), (var b, var a): // expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}} expected-warning {{variable 'b' was never used; consider replacing with '_' or removing it}}
235235
()
236236

237237
case (_, 2): // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{13-13= break}}
@@ -251,7 +251,7 @@ func patternVarUsedInAnotherPattern(x: Int) {
251251
switch t {
252252
case (1, 2):
253253
fallthrough // expected-error {{'fallthrough' cannot transfer control to a case label that declares variables}}
254-
case (var a, var b):
254+
case (var a, var b): // expected-warning {{variable 'a' was never mutated; consider changing to 'let' constant}} expected-warning {{variable 'b' was never mutated; consider changing to 'let' constant}}
255255
t = (b, a)
256256
}
257257

test/decl/func/throwing_functions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ var c4 : () -> Int = {() throws -> Int in 0} // expected-error{{invalid conversi
117117
var c5 : () -> Int = { try c2() } // expected-error{{invalid conversion from throwing function of type '() throws -> Int' to non-throwing function type '() -> Int'}}
118118
var c6 : () throws -> Int = { do { _ = try c2() } ; return 0 }
119119
var c7 : () -> Int = { do { try c2() } ; return 0 } // expected-error{{invalid conversion from throwing function of type '() throws -> _' to non-throwing function type '() -> Int'}}
120-
var c8 : () -> Int = { do { _ = try c2() } catch _ { var x = 0 } ; return 0 }
120+
var c8 : () -> Int = { do { _ = try c2() } catch _ { var x = 0 } ; return 0 } // expected-warning {{initialization of variable 'x' was never used; consider replacing with assignment to '_' or removing it}}
121121
var c9 : () -> Int = { do { try c2() } catch Exception.A { var x = 0 } ; return 0 }// expected-error{{invalid conversion from throwing function of type '() throws -> _' to non-throwing function type '() -> Int'}}
122122
var c10 : () -> Int = { throw Exception.A; return 0 } // expected-error{{invalid conversion from throwing function of type '() throws -> _' to non-throwing function type '() -> Int'}}
123123
var c11 : () -> Int = { try! c2() }

test/decl/var/usage.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,18 @@ func test2() {
253253
let (d): Int = 9 // expected-warning {{immutable value 'd' was never used; consider replacing with '_' or removing it}} {{8-9=_}}
254254
}
255255

256-
for i in 0..<10 { // expected-warning {{immutable value 'i' was never used; consider replacing with '_' or removing it}} {{5-6=_}}
257-
print("")
258-
}
259-
260-
// Due to the complexities of global variable tracing, these will not generate warnings
261-
let unusedVariable = ""
262-
var unNeededVar = false
263-
if unNeededVar {}
264-
265256
let optionalString: String? = "check"
266257
if let string = optionalString {} // expected-warning {{value 'string' was defined but never used; consider replacing with boolean test}} {{4-17=}} {{31-31= != nil}}
267258

268259
let optionalAny: Any? = "check"
269260
if let string = optionalAny as? String {} // expected-warning {{value 'string' was defined but never used; consider replacing with boolean test}} {{4-17=(}} {{39-39=) != nil}}
270261

262+
// Due to the complexities of global variable tracing, these will not generate warnings
263+
let unusedVariable = ""
264+
var unNeededVar = false
265+
if unNeededVar {}
266+
guard let foo = optionalAny else {}
267+
268+
for i in 0..<10 { // expected-warning {{immutable value 'i' was never used; consider replacing with '_' or removing it}} {{5-6=_}}
269+
print("")
270+
}

test/decl/var/variables.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var aot2 = aot1 // expected-warning {{variable 'aot2' inferred to have
4848

4949

5050
for item in [AnyObject]() { // No warning in for-each loop.
51+
_ = item
5152
}
5253

5354

@@ -99,6 +100,7 @@ func test21081340() {
99100
if true {
100101
let s : Int
101102
s = 42 // should be valid.
103+
_ = s
102104
}
103105

104106

test/expr/cast/array_iteration.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rootView.subviews = v
1212

1313
_ = rootView.subviews as! [View]
1414

15-
for view in rootView.subviews as! [View] {
15+
for view in rootView.subviews as! [View] { // expected-warning{{immutable value 'view' was never used; consider replacing with '_' or removing it}}
1616
doFoo()
1717
}
1818

@@ -32,18 +32,18 @@ _ = ao as! [View] // works
3232

3333
var b = Array<(String, Int)>()
3434

35-
for x in b {
35+
for x in b { // expected-warning{{immutable value 'x' was never used; consider replacing with '_' or removing it}}
3636
doFoo()
3737
}
3838

3939
var c : Array<(String, Int)>! = Array()
4040

41-
for x in c {
41+
for x in c { // expected-warning{{immutable value 'x' was never used; consider replacing with '_' or removing it}}
4242
doFoo()
4343
}
4444

4545
var d : Array<(String, Int)>? = Array()
4646

47-
for x in d! {
47+
for x in d! { // expected-warning{{immutable value 'x' was never used; consider replacing with '_' or removing it}}
4848
doFoo()
4949
}

test/expr/cast/as_coerce.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ if cc is P {
5555
}
5656
if let p = cc as? P {
5757
doFoo()
58+
_ = p
5859
}
5960

6061
// Test that 'as?' coercion fails.

test/stmt/if_while_var.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ if let x = foo() {
5757

5858
var opt: Int? = .none
5959

60-
if let x = opt {}
61-
if var x = opt {}
60+
if let x = opt {} // expected-warning {{value 'x' was defined but never used; consider replacing with boolean test}}
61+
if var x = opt {} // expected-warning {{value 'x' was defined but never used; consider replacing with boolean test}}
6262

6363
// <rdar://problem/20800015> Fix error message for invalid if-let
6464
let someInteger = 1
@@ -67,21 +67,21 @@ if case let y? = someInteger {} // expected-error {{'?' pattern cannot match va
6767

6868
// Test multiple clauses on "if let".
6969
if let x = opt, let y = opt, x != y,
70-
let a = opt, var b = opt {
70+
let a = opt, var b = opt { // expected-warning {{immutable value 'a' was never used; consider replacing with '_' or removing it}} expected-warning {{variable 'b' was never used; consider replacing with '_' or removing it}}
7171
}
7272

7373
// Leading boolean conditional.
7474
if 1 != 2, let x = opt,
7575
y = opt, // expected-error {{expected 'let' in conditional}} {{4-4=let }}
7676
x != y,
77-
let a = opt, var b = opt {
77+
let a = opt, var b = opt { // expected-warning {{immutable value 'a' was never used; consider replacing with '_' or removing it}} expected-warning {{variable 'b' was never used; consider replacing with '_' or removing it}}
7878
}
7979

8080
// <rdar://problem/20457938> typed pattern is not allowed on if/let condition
81-
if 1 != 2, let x : Int? = opt {}
81+
if 1 != 2, let x : Int? = opt {} // expected-warning {{immutable value 'x' was never used; consider replacing with '_' or removing it}}
8282
// expected-warning @-1 {{explicitly specified type 'Int?' adds an additional level of optional to the initializer, making the optional check always succeed}} {{20-26=Int}}
8383

84-
if 1 != 2, case let x? : Int? = 42 {}
84+
if 1 != 2, case let x? : Int? = 42 {} // expected-warning {{immutable value 'x' was never used; consider replacing with '_' or removing it}}
8585
// expected-warning @-1 {{non-optional expression of type 'Int' used in a check for optionals}}
8686

8787

@@ -91,7 +91,7 @@ if 1 != 2, case let x? : Int? = 42 {}
9191
if 1 != 2, { // expected-error {{'() -> ()' is not convertible to 'Bool'}}
9292
} // expected-error {{expected '{' after 'if' condition}}
9393
if 1 != 2, 4 == 57 {}
94-
if 1 != 2, 4 == 57, let x = opt {}
94+
if 1 != 2, 4 == 57, let x = opt {} // expected-warning {{immutable value 'x' was never used; consider replacing with '_' or removing it}}
9595

9696
// Test that these don't cause the parser to crash.
9797
if true { if a == 0; {} } // expected-error {{expected '{' after 'if' condition}} expected-error 3{{}}

0 commit comments

Comments
 (0)