Skip to content

Commit edc193e

Browse files
author
Brian King
committed
Fix warnings in top level statements
1 parent 6091cda commit edc193e

File tree

8 files changed

+44
-28
lines changed

8 files changed

+44
-28
lines changed

test/ClangImporter/blocks_parse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func checkTypeImpl<T>(_ a: inout T, _: T.Type) {}
3232
do {
3333
var blockOpt = blockWithoutNullability()
3434
checkTypeImpl(&blockOpt, Optional<my_block_t>.self)
35-
var block: my_block_t = blockWithoutNullability()
35+
var _: my_block_t = blockWithoutNullability()
3636
}
3737
do {
3838
var block = blockWithNonnull()
@@ -41,7 +41,7 @@ do {
4141
do {
4242
var blockOpt = blockWithNullUnspecified()
4343
checkTypeImpl(&blockOpt, Optional<my_block_t>.self)
44-
var block: my_block_t = blockWithNullUnspecified()
44+
var _: my_block_t = blockWithNullUnspecified()
4545
}
4646
do {
4747
var block = blockWithNullable()

test/Constraints/operator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ do {
66
let a: String? = "a"
77
let b: String? = "b"
88
let c: String? = "c"
9-
let d: String? = a! + b! + c!
9+
let _: String? = a! + b! + c!
1010

1111
let x: Double = 1
1212
_ = x + x + x

test/Parse/brace_recovery_eof.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
// Make sure source ranges satisfy the verifier.
44
for foo in [1, 2] { // expected-note {{to match this opening '{'}}
5-
var x = foo
5+
_ = foo
66
// expected-error@+1{{expected '}' at end of brace statement}}

test/Parse/c_function_pointers.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,36 @@ if true {
1616
func localWithContext() -> Int { return x }
1717

1818
let a: @convention(c) () -> Int = global
19-
let a2: @convention(c) () -> Int = main.global
20-
let b: @convention(c) () -> Int = { 0 }
21-
let c: @convention(c) () -> Int = local
19+
let _: @convention(c) () -> Int = main.global
20+
let _: @convention(c) () -> Int = { 0 }
21+
let _: @convention(c) () -> Int = local
2222

2323
// Can't convert a closure with context to a C function pointer
24-
let d: @convention(c) () -> Int = { x } // expected-error{{cannot be formed from a closure that captures context}}
25-
let d2: @convention(c) () -> Int = { [x] in x } // expected-error{{cannot be formed from a closure that captures context}}
26-
let e: @convention(c) () -> Int = localWithContext // expected-error{{cannot be formed from a local function that captures context}}
24+
let _: @convention(c) () -> Int = { x } // expected-error{{cannot be formed from a closure that captures context}}
25+
let _: @convention(c) () -> Int = { [x] in x } // expected-error{{cannot be formed from a closure that captures context}}
26+
let _: @convention(c) () -> Int = localWithContext // expected-error{{cannot be formed from a local function that captures context}}
2727

2828
// Can't convert a closure value to a C function pointer
2929
let global2 = global
30-
let f: @convention(c) () -> Int = global2 // expected-error{{can only be formed from a reference to a 'func' or a literal closure}}
30+
let _: @convention(c) () -> Int = global2 // expected-error{{can only be formed from a reference to a 'func' or a literal closure}}
3131
let globalBlock: @convention(block) () -> Int = global
32-
let g: @convention(c) () -> Int = globalBlock // expected-error{{can only be formed from a reference to a 'func' or a literal closure}}
32+
let _: @convention(c) () -> Int = globalBlock // expected-error{{can only be formed from a reference to a 'func' or a literal closure}}
3333

3434
// Can convert a function pointer to a block or closure, or assign to another
3535
// C function pointer
36-
let h: @convention(c) () -> Int = a
37-
let i: @convention(block) () -> Int = a
38-
let j: () -> Int = a
36+
let _: @convention(c) () -> Int = a
37+
let _: @convention(block) () -> Int = a
38+
let _: () -> Int = a
3939

4040
// Can't convert a C function pointer from a method.
4141
// TODO: Could handle static methods.
42-
let k: @convention(c) () -> Int = S.staticMethod // expected-error{{}}
43-
let m: @convention(c) () -> Int = C.staticMethod // expected-error{{}}
44-
let n: @convention(c) () -> Int = C.classMethod // expected-error{{}}
42+
let _: @convention(c) () -> Int = S.staticMethod // expected-error{{}}
43+
let _: @convention(c) () -> Int = C.staticMethod // expected-error{{}}
44+
let _: @convention(c) () -> Int = C.classMethod // expected-error{{}}
4545

4646
// <rdar://problem/22181714> Crash when typing "signal"
4747
let iuo_global: (() -> Int)! = global
48-
let p: (@convention(c) () -> Int)! = iuo_global // expected-error{{a C function pointer can only be formed from a reference to a 'func' or a literal closure}}
48+
let _: (@convention(c) () -> Int)! = iuo_global // expected-error{{a C function pointer can only be formed from a reference to a 'func' or a literal closure}}
4949

5050
func handler(_ callback: (@convention(c) () -> Int)!) {}
5151
handler(iuo_global) // expected-error{{a C function pointer can only be formed from a reference to a 'func' or a literal closure}}

test/decl/func/throwing_functions_without_try.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ doLazy(foo())
2222

2323
// It doesn't include explicit closures.
2424
var closure: () -> () = {
25-
var x = foo() // expected-error {{call can throw, but it is not marked with 'try' and the error is not handled}}
25+
_ = foo() // expected-error {{call can throw, but it is not marked with 'try' and the error is not handled}}
2626
doLazy(foo()) // expected-error {{call can throw but is not marked with 'try'}}
2727
}
2828

test/decl/var/usage.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,19 @@ func test2() {
252252
var c: Int = 4 // expected-warning {{variable 'c' was never used; consider replacing with '_' or removing it}} {{7-8=_}}
253253
let (d): Int = 9 // expected-warning {{immutable value 'd' was never used; consider replacing with '_' or removing it}} {{8-9=_}}
254254
}
255+
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+
265+
let optionalString: String? = "check"
266+
if let string = optionalString {} // expected-warning {{value 'string' was defined but never used; consider replacing with boolean test}} {{4-17=}} {{31-31= != nil}}
267+
268+
let optionalAny: Any? = "check"
269+
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}}
270+

test/expr/cast/dictionary_downcast.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ var dictDC = dictCC as! Dictionary<D, C>
2929
var dictDD = dictCC as! Dictionary<D, D>
3030

3131
// Test dictionary conditional downcasts
32-
if let dictCD = dictCC as? Dictionary<C, D> { }
33-
if let dictDC = dictCC as? Dictionary<D, C> { }
34-
if let dictDD = dictCC as? Dictionary<D, D> { }
32+
if let _ = dictCC as? Dictionary<C, D> { }
33+
if let _ = dictCC as? Dictionary<D, C> { }
34+
if let _ = dictCC as? Dictionary<D, D> { }
3535

3636
// Test dictionary downcasts to unrelated types.
3737
dictCC as Dictionary<D, U> // expected-error{{cannot convert value of type 'Dictionary<C, C>' to type 'Dictionary<D, U>' in coercion}}
3838
dictCC as Dictionary<U, D> // expected-error{{cannot convert value of type 'Dictionary<C, C>' to type 'Dictionary<U, D>' in coercion}}
3939
dictCC as Dictionary<U, U> // expected-error{{cannot convert value of type 'Dictionary<C, C>' to type 'Dictionary<U, U>' in coercion}}
4040

4141
// Test dictionary conditional downcasts to unrelated types
42-
if let dictDU = dictCC as? Dictionary<D, U> { } // expected-warning{{cast from 'Dictionary<C, C>' to unrelated type 'Dictionary<D, U>' always fails}}
43-
if let dictUD = dictCC as? Dictionary<U, D> { } // expected-warning{{cast from 'Dictionary<C, C>' to unrelated type 'Dictionary<U, D>' always fails}}
44-
if let dictUU = dictCC as? Dictionary<U, U> { } // expected-warning{{cast from 'Dictionary<C, C>' to unrelated type 'Dictionary<U, U>' always fails}}
42+
if let _ = dictCC as? Dictionary<D, U> { } // expected-warning{{cast from 'Dictionary<C, C>' to unrelated type 'Dictionary<D, U>' always fails}}
43+
if let _ = dictCC as? Dictionary<U, D> { } // expected-warning{{cast from 'Dictionary<C, C>' to unrelated type 'Dictionary<U, D>' always fails}}
44+
if let _ = dictCC as? Dictionary<U, U> { } // expected-warning{{cast from 'Dictionary<C, C>' to unrelated type 'Dictionary<U, U>' always fails}}
4545

test/expr/cast/set_downcast.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ var setD = Set<D>()
2929
setD = setC as! Set<D>
3030

3131
// Test set conditional downcasts
32-
if let setD = setC as? Set<D> { }
32+
if let _ = setC as? Set<D> { }
3333

3434
// Test set downcasts to unrelated types.
3535
_ = setC as! Set<U> // expected-warning{{cast from 'Set<C>' to unrelated type 'Set<U>' always fails}}
3636

3737
// Test set conditional downcasts to unrelated types
38-
if let setU = setC as? Set<U> { } // expected-warning{{cast from 'Set<C>' to unrelated type 'Set<U>' always fails}}
38+
if let _ = setC as? Set<U> { } // expected-warning{{cast from 'Set<C>' to unrelated type 'Set<U>' always fails}}

0 commit comments

Comments
 (0)