mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
<rdar://problem/15975935> warning that you can use 'let' not 'var' <rdar://problem/18876585> Compiler should warn me if I set a parameter as 'var' but never modify it <rdar://problem/17224539> QoI: warn about unused variables This uses a simple pass in MiscDiagnostics that walks the body of an AbstractFunctionDecl. This means that it doesn't warn about unused properties (etc), but it captures a vast majority of the cases. It also does not warn about unused parameters (as a policy decision) because it is too noisy, there are a variety of other refinements that could be done as well, thoughts welcome. Swift SVN r28412
15 lines
1.0 KiB
Swift
15 lines
1.0 KiB
Swift
// RUN: %target-parse-verify-swift
|
|
|
|
// Warn about non-trailing closures followed by parameters with
|
|
// default arguments.
|
|
func f1(f: () -> (), bar: Int = 10) { } // expected-warning{{closure parameter prior to parameters with default arguments will not be treated as a trailing closure}}
|
|
func f2(f: (() -> ())!, bar: Int = 10, wibble: Int = 17) { } // expected-warning{{closure parameter prior to parameters with default arguments will not be treated as a trailing closure}}
|
|
func f3(f: (() -> ())?, bar: Int = 10) { } // expected-warning{{closure parameter prior to parameters with default arguments will not be treated as a trailing closure}}
|
|
func f4(var f: (() -> ())?, bar: Int = 10) { } // expected-warning{{closure parameter prior to parameters with default arguments will not be treated as a trailing closure}} expected-warning {{parameter 'f' was never mutated}}
|
|
|
|
// An extra set of parentheses suppresses the warning.
|
|
func g1(f: (() -> ()), bar: Int = 10) { } // no-warning
|
|
|
|
// Stop at the first closure.
|
|
func g2(f: () -> (), g: (() -> ())? = nil) { } // no-warning
|