From 93b6962478056640336f4b40d218e922c623d0d8 Mon Sep 17 00:00:00 2001 From: David Farler Date: Tue, 3 Nov 2015 17:20:10 -0800 Subject: [PATCH] Warn when using 'var' bindings in function parameters These will no longer be allowed in a future Swift release. rdar://problem/23172698 --- include/swift/AST/Decl.h | 3 +++ include/swift/AST/DiagnosticsParse.def | 2 +- lib/AST/Decl.cpp | 8 +++++- lib/Parse/ParsePattern.cpp | 8 ++++-- test/1_stdlib/CollectionDiagnostics.swift | 12 ++++++--- test/ClangModules/ctypes_parse_union.swift | 6 +++-- test/ClangModules/objc_parse.swift | 2 +- test/Constraints/bridging.swift | 3 ++- test/Constraints/closures.swift | 4 ++- test/Constraints/diagnostics.swift | 4 ++- test/Constraints/keyword_arguments.swift | 6 ++++- test/Constraints/lvalues.swift | 3 ++- test/Constraints/members.swift | 6 +++-- test/Constraints/subscript.swift | 7 +++--- test/Constraints/tuple.swift | 5 ++-- test/Constraints/unchecked_optional.swift | 6 +++-- test/DebugInfo/autoclosure.swift | 3 ++- test/Generics/algorithms.swift | 25 +++++++++++++------ test/Generics/function_defs.swift | 1 - test/Generics/generic_types.swift | 3 ++- test/Generics/same_type_constraints.swift | 13 +++++++--- test/IDE/print_ast_tc_decls.swift | 6 ++++- test/Parse/pointer_conversion.swift | 9 ++++--- test/SILGen/statements.swift | 13 +++++++--- .../writeback_conflict_diagnostics.swift | 6 +++-- test/SILPasses/mandatory_inlining.swift | 4 +-- test/SILPasses/switch.swift | 3 ++- test/Sema/accessibility_multi.swift | 6 +++-- test/Sema/immutability.swift | 24 ++++++++++-------- test/attr/attr_autoclosure.swift | 2 +- test/attr/attr_objc.swift | 6 +++-- test/attr/attr_warn_unused_result.swift | 3 ++- test/decl/class/override.swift | 20 +++++++-------- test/decl/ext/protocol.swift | 4 ++- test/decl/func/dynamic_self.swift | 6 +++-- test/decl/func/functions.swift | 9 ++++--- test/decl/func/trailing_closures.swift | 2 +- test/decl/inherit/initializer.swift | 4 +-- test/decl/var/usage.swift | 13 ++++++---- test/expr/cast/bridged.swift | 4 ++- test/expr/closure/closures.swift | 5 ++-- test/expr/expressions.swift | 2 +- test/expr/postfix/call/construction.swift | 3 ++- 43 files changed, 185 insertions(+), 99 deletions(-) diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 90704852ebfb1..02ca5b4a1b904 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -4151,6 +4151,9 @@ class VarDecl : public AbstractStorageDecl { /// that it can be rewritten to a 'var'. This is used in situations where the /// compiler detects obvious attempts to mutate a constant. void emitLetToVarNoteIfSimple(DeclContext *UseDC) const; + + /// Returns true if the name is the self identifier and is implicit. + bool isImplicitSelf() const; // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { diff --git a/include/swift/AST/DiagnosticsParse.def b/include/swift/AST/DiagnosticsParse.def index 556dcda4ade22..c647d44e111b4 100644 --- a/include/swift/AST/DiagnosticsParse.def +++ b/include/swift/AST/DiagnosticsParse.def @@ -642,7 +642,7 @@ ERROR(untyped_pattern_ellipsis,pattern_parsing,none, ERROR(non_func_decl_pattern_init,pattern_parsing,none, "default argument is only permitted for a non-curried function parameter",()) WARNING(var_not_allowed_in_pattern,pattern_parsing, none, - "Use of 'var' binding here is deprecated and will be removed in a future version of Swift", ()) + "Use of '%select{var|let}0' binding here is deprecated and will be removed in a future version of Swift", (unsigned)) ERROR(var_pattern_in_var,pattern_parsing,none, "'%select{var|let}0' cannot appear nested inside another 'var' or " "'let' pattern", (unsigned)) diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 5949f562215c3..09d06360e3ea6 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -3154,6 +3154,9 @@ Pattern *VarDecl::getParentPattern() const { return nullptr; } +bool VarDecl::isImplicitSelf() const { + return isImplicit() && getName() == getASTContext().Id_self; +} /// Return true if this stored property needs to be accessed with getters and /// setters for Objective-C. @@ -3232,9 +3235,12 @@ void VarDecl::emitLetToVarNoteIfSimple(DeclContext *UseDC) const { // If it isn't a 'let', don't touch it. if (!isLet()) return; + // Don't suggest mutability for explicit function parameters + if (isa(this) && !isImplicitSelf()) return; + // If this is the 'self' argument of a non-mutating method in a value type, // suggest adding 'mutating' to the method. - if (getName().str() == "self" && UseDC) { + if (isImplicitSelf() && UseDC) { // If the problematic decl is 'self', then we might be trying to mutate // a property in a non-mutating method. auto FD = dyn_cast(UseDC->getInnermostMethodContext()); diff --git a/lib/Parse/ParsePattern.cpp b/lib/Parse/ParsePattern.cpp index 9c7ce9afa4c71..35312a07bde1d 100644 --- a/lib/Parse/ParsePattern.cpp +++ b/lib/Parse/ParsePattern.cpp @@ -179,9 +179,13 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc, param.LetVarInOutLoc = consumeToken(); param.SpecifierKind = ParsedParameter::InOut; } else if (Tok.is(tok::kw_let)) { + diagnose(Tok.getLoc(), diag::var_not_allowed_in_pattern, + Tok.is(tok::kw_let)).fixItRemove(Tok.getLoc()); param.LetVarInOutLoc = consumeToken(); param.SpecifierKind = ParsedParameter::Let; } else if (Tok.is(tok::kw_var)) { + diagnose(Tok.getLoc(), diag::var_not_allowed_in_pattern, + Tok.is(tok::kw_let)).fixItRemove(Tok.getLoc()); param.LetVarInOutLoc = consumeToken(); param.SpecifierKind = ParsedParameter::Var; } @@ -851,7 +855,7 @@ ParserResult Parser::parsePattern() { } else { // In an always immutable context, `var` is not allowed. if (alwaysImmutable) - diagnose(varLoc, diag::var_not_allowed_in_pattern) + diagnose(varLoc, diag::var_not_allowed_in_pattern, isLetKeyword) .fixItRemove(varLoc); } @@ -1063,7 +1067,7 @@ ParserResult Parser::parseMatchingPatternAsLetOrVar(bool isLet, diagnose(varLoc, diag::let_pattern_in_immutable_context); if (!isLet && InVarOrLetPattern == IVOLP_AlwaysImmutable) - diagnose(varLoc, diag::var_not_allowed_in_pattern) + diagnose(varLoc, diag::var_not_allowed_in_pattern, isLet) .fixItReplace(varLoc, "let"); // In our recursive parse, remember that we're in a var/let pattern. diff --git a/test/1_stdlib/CollectionDiagnostics.swift b/test/1_stdlib/CollectionDiagnostics.swift index 496b59c0daca4..1c4d8b7717065 100644 --- a/test/1_stdlib/CollectionDiagnostics.swift +++ b/test/1_stdlib/CollectionDiagnostics.swift @@ -44,10 +44,13 @@ func sortResultIgnored< S.Generator.Element : Comparable, MC.Generator.Element : Comparable >( - var sequence: S, // expected-warning {{parameter 'sequence' was never mutated; consider changing to 'let' constant}} {{3-7=}} - var mutableCollection: MC, // expected-warning {{parameter 'mutableCollection' was never mutated; consider changing to 'let' constant}} {{3-7=}} - var array: [Int] // expected-warning {{parameter 'array' was never mutated; consider changing to 'let' constant}} {{3-7=}} + sequence: S, + mutableCollection: MC, + array: [Int] ) { + var sequence = sequence // expected-warning {{was never mutated; consider changing to 'let' constant}} + var mutableCollection = mutableCollection // expected-warning {{was never mutated; consider changing to 'let' constant}} + var array = array // expected-warning {{was never mutated; consider changing to 'let' constant}} sequence.sort() // expected-warning {{result of call to 'sort()' is unused}} sequence.sort { $0 < $1 } // expected-warning {{result of call to 'sort' is unused}} @@ -359,7 +362,8 @@ struct MyCollection : Sliceable {} // expected-error {{'Sliceable' has been rena protocol MyProtocol : Sliceable {} // expected-error {{'Sliceable' has been renamed to 'CollectionType'}} {{23-32=CollectionType}} func processCollection(e: E) {} // expected-error {{'Sliceable' has been renamed to 'CollectionType'}} {{28-37=CollectionType}} -func renamedRangeReplaceableCollectionTypeMethods(var c: DefaultedForwardRangeReplaceableCollection) { +func renamedRangeReplaceableCollectionTypeMethods(c: DefaultedForwardRangeReplaceableCollection) { + var c = c c.extend([ 10 ]) // expected-error {{'extend' has been renamed to 'appendContentsOf'}} {{5-11=appendContentsOf}} c.splice([ 10 ], atIndex: c.startIndex) // expected-error {{'splice(_:atIndex:)' has been renamed to 'insertContentsOf'}} {{5-11=insertContentsOf}} } diff --git a/test/ClangModules/ctypes_parse_union.swift b/test/ClangModules/ctypes_parse_union.swift index 24ae5f638bad4..deb2575349566 100644 --- a/test/ClangModules/ctypes_parse_union.swift +++ b/test/ClangModules/ctypes_parse_union.swift @@ -2,7 +2,8 @@ import ctypes -func useStructWithUnion(var vec: GLKVector4) -> GLKVector4 { +func useStructWithUnion(vec: GLKVector4) -> GLKVector4 { + var vec = vec _ = vec.v.0 _ = vec.v.1 _ = vec.v.2 @@ -57,7 +58,8 @@ func useStructWithAnonymousUnion(u: AnonUnion) -> AnonUnion { return u } -func useStructWithUnnamedUnion(var u: UnnamedUnion) -> UnnamedUnion { +func useStructWithUnnamedUnion(u: UnnamedUnion) -> UnnamedUnion { + var u = u u.u.i = 100 u.u.f = 1.0 } diff --git a/test/ClangModules/objc_parse.swift b/test/ClangModules/objc_parse.swift index b49380a0d8d61..b15e0bc918955 100644 --- a/test/ClangModules/objc_parse.swift +++ b/test/ClangModules/objc_parse.swift @@ -106,7 +106,7 @@ func dynamicLookupMethod(b: AnyObject) { } // Properties -func properties(b: B) { // expected-note {{mark parameter with 'var' to make it mutable}} {{17-17=var }} +func properties(b: B) { var i = b.counter b.counter = i + 1 i = i + b.readCounter diff --git a/test/Constraints/bridging.swift b/test/Constraints/bridging.swift index c53a316b8eb67..fa9f1630752db 100644 --- a/test/Constraints/bridging.swift +++ b/test/Constraints/bridging.swift @@ -241,7 +241,8 @@ func rdar19831698() { } // Incorrect fixit for NSString? to String? conversions -func rdar19836341(ns: NSString?, var vns: NSString?) { +func rdar19836341(ns: NSString?, vns: NSString?) { + var vns = vns let _: String? = ns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}} var _: String? = ns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}} // FIXME: there should be a fixit appending "as String?" to the line; for now diff --git a/test/Constraints/closures.swift b/test/Constraints/closures.swift index c347fd70c1f3b..68455aba6555d 100644 --- a/test/Constraints/closures.swift +++ b/test/Constraints/closures.swift @@ -48,8 +48,10 @@ struct X3 { init(_: (T)->()) {} } -func testX3(var x: Int) { +func testX3(x: Int) { + var x = x _ = X3({ x = $0 }) + _ = x } // diff --git a/test/Constraints/diagnostics.swift b/test/Constraints/diagnostics.swift index 57ab1c67d30fd..7c5c9b06f58c1 100644 --- a/test/Constraints/diagnostics.swift +++ b/test/Constraints/diagnostics.swift @@ -424,7 +424,9 @@ zip(numbers, numbers).filter { $0.2 > 1 } // expected-error {{value of tuple ty // QoI: Cannot invoke 'function' with an argument list of type 'type' func foo20868864(callback: ([String]) -> ()) { } -func rdar20868864(var s: String) { + +func rdar20868864(s: String) { + var s = s foo20868864 { (strings: [String]) in s = strings // expected-error {{cannot assign value of type '[String]' to type 'String'}} } diff --git a/test/Constraints/keyword_arguments.swift b/test/Constraints/keyword_arguments.swift index 5e5630fe229cd..9714dd4f9087d 100644 --- a/test/Constraints/keyword_arguments.swift +++ b/test/Constraints/keyword_arguments.swift @@ -295,7 +295,11 @@ trailingclosure1(x: 1, { return 5 }) // expected-error{{missing argument label ' func trailingclosure2(x x: Int, f: (() -> Int)!...) {} trailingclosure2(x: 5) { return 5 } -func trailingclosure3(x x: Int, var f: (() -> Int)!) { f = nil} +func trailingclosure3(x x: Int, f: (() -> Int)!) { + var f = f + _ = f + f = nil +} trailingclosure3(x: 5) { return 5 } func trailingclosure4(f f: () -> Int) {} diff --git a/test/Constraints/lvalues.swift b/test/Constraints/lvalues.swift index 242f96b14483c..985d5ba930c19 100644 --- a/test/Constraints/lvalues.swift +++ b/test/Constraints/lvalues.swift @@ -174,7 +174,8 @@ takeArrayRef(["asdf", "1234"]) // expected-error{{contextual type 'inout Array Reference to value from array changed func rdar19835413() { func f1(p: UnsafeMutablePointer) {} - func f2(var a: [Int], i: Int, pi: UnsafeMutablePointer) { + func f2(a: [Int], i: Int, pi: UnsafeMutablePointer) { + var a = a f1(&a) f1(&a[i]) f1(&a[0]) diff --git a/test/Constraints/members.swift b/test/Constraints/members.swift index 37050d660da97..0fea005c95214 100644 --- a/test/Constraints/members.swift +++ b/test/Constraints/members.swift @@ -187,7 +187,8 @@ protocol ClassP : class { func bas(x: Int) } -func generic(var t: T) { +func generic(t: T) { + var t = t // Instance member of archetype let _: Int -> () = id(t.bar) let _: () = id(t.bar(0)) @@ -250,7 +251,8 @@ func genericClassP(t: T) { // Members of existentials //// -func existential(var p: P) { +func existential(p: P) { + var p = p // Fully applied mutating method p.mut(1) _ = p.mut // expected-error{{partial application of 'mutating' method is not allowed}} diff --git a/test/Constraints/subscript.swift b/test/Constraints/subscript.swift index 7e6ad47b09a9c..2ab1c2a203475 100644 --- a/test/Constraints/subscript.swift +++ b/test/Constraints/subscript.swift @@ -72,11 +72,12 @@ let _ = 1["1"] // expected-error {{ambiguous use of 'subscript'}} // rdar://17687826 - QoI: error message when reducing to an untyped dictionary isn't helpful -let squares = [ 1, 2, 3 ].reduce([:]) { (var dict, n) in // expected-error {{cannot invoke 'reduce' with an argument list of type '([_ : _], @noescape (_, Int) throws -> _)'}} +let squares = [ 1, 2, 3 ].reduce([:]) { (dict, n) in // expected-error {{cannot invoke 'reduce' with an argument list of type '([_ : _], @noescape (_, Int) throws -> _)'}} // expected-note @-1 {{expected an argument list of type '(T, combine: @noescape (T, Self.Generator.Element) throws -> T)'}} + var dict = dict // expected-error {{type of expression is ambiguous without more context}} - dict[n] = n * n // expected-error {{type of expression is ambiguous without more context}} - return dict // expected-error {{type of expression is ambiguous without more context}} + dict[n] = n * n + return dict } diff --git a/test/Constraints/tuple.swift b/test/Constraints/tuple.swift index 839dd36e6b0cd..7b32c8fe584f0 100644 --- a/test/Constraints/tuple.swift +++ b/test/Constraints/tuple.swift @@ -91,7 +91,8 @@ class C { func f(_: C) {} } -func testLValue(var c: C) { +func testLValue(c: C) { + var c = c c.f(c) let x = c @@ -100,7 +101,7 @@ func testLValue(var c: C) { // Crash in TypeChecker::coercePatternToType -func invalidPatternCrash(let k : Int) { +func invalidPatternCrash(k : Int) { switch k { case (k, cph_: k) as UInt8: // expected-error {{tuple pattern cannot match values of the non-tuple type 'UInt8'}} expected-warning {{cast from 'Int' to unrelated type 'UInt8' always fails}} break diff --git a/test/Constraints/unchecked_optional.swift b/test/Constraints/unchecked_optional.swift index 6fe4a67c687e1..d20a36a3d7064 100644 --- a/test/Constraints/unchecked_optional.swift +++ b/test/Constraints/unchecked_optional.swift @@ -36,7 +36,8 @@ struct B { var x : Int } -func test2(var b : B!) { +func test2(b : B!) { + var b = b let x = b.x b.x = x b = nil @@ -85,7 +86,8 @@ func test10(x : Int?) -> Int! { return test10_helper(x) } protocol P11 { } extension Int : P11 { } func test11_helper(t: T) { } -func test11(i: Int!, var j: Int!) { +func test11(i: Int!, j: Int!) { + var j = j test11_helper(i) test11_helper(j) j = nil diff --git a/test/DebugInfo/autoclosure.swift b/test/DebugInfo/autoclosure.swift index 4d76e71fe3ce3..a337784f1c9ad 100644 --- a/test/DebugInfo/autoclosure.swift +++ b/test/DebugInfo/autoclosure.swift @@ -18,7 +18,8 @@ func &&&&&(lhs: BooleanType, @autoclosure rhs: ()->BooleanType) -> Bool { return lhs.boolValue ? rhs().boolValue : false } -func call_me(var input: Int64) -> Void { +func call_me(input: Int64) -> Void { + var input = input // rdar://problem/14627460 // An autoclosure should have a line number in the debug info and a scope line of 0. // CHECK-DAG: !DISubprogram({{.*}}linkageName: "_TFF11autoclosure7call_meFVs5Int64T_u_KT_Ps11BooleanType_",{{.*}} line: [[@LINE+3]],{{.*}} isLocal: false, isDefinition: true diff --git a/test/Generics/algorithms.swift b/test/Generics/algorithms.swift index a1b10b7ef7af0..4322ab6becb22 100644 --- a/test/Generics/algorithms.swift +++ b/test/Generics/algorithms.swift @@ -61,8 +61,10 @@ func countIf< func equal - (var range1 : R1, var range2 : R2) -> Bool { + (range1 : R1, range2 : R2) -> Bool { + var range1 = range1 + var range2 = range2 var e1 = range1.next() var e2 = range2.next() @@ -77,8 +79,10 @@ func equal - (var range1 : R1, var range2 : R2, + (range1 : R1, range2 : R2, predicate : (R1.Element, R2.Element)-> Bool) -> Bool { + var range1 = range1 + var range2 = range2 var e1 = range1.next() var e2 = range2.next() @@ -94,7 +98,9 @@ func equalIf func mismatch - (var range1 : R1, var range2 : R2) -> (R1, R2) { + (range1 : R1, range2 : R2) -> (R1, R2) { + var range1 = range1 + var range2 = range2 var prev1 = range1, prev2 = range2 while true { @@ -109,8 +115,10 @@ func mismatch - (var range1 : R1, var range2 : R2, + (range1 : R1, range2 : R2, predicate : (R1.Element, R2.Element) -> Bool) -> (R1, R2) { + var range1 = range1 + var range2 = range2 var prev1 = range1, prev2 = range2 while true { @@ -124,8 +132,9 @@ func mismatchIf return (prev1, prev2) } -func minElement(var range: R) +func minElement(range: R) -> R.Element { + var range = range var result = range.next()! for next in GeneratorSequence(range) { if next < result { @@ -135,8 +144,9 @@ func minElement(var range: R) return result } -func maxElement(var range: R) +func maxElement(range: R) -> R.Element { + var range = range var result = range.next()! for next in GeneratorSequence(range) { if next > result { @@ -146,8 +156,9 @@ func maxElement(var range: R) return result } -func minMaxElement(var range: R) +func minMaxElement(range: R) -> (R.Element, R.Element) { + var range = range var min = range.next()!, max = min for next in GeneratorSequence(range) { if next < min { min = next } diff --git a/test/Generics/function_defs.swift b/test/Generics/function_defs.swift index cb7956f715c71..60d06790f2be4 100644 --- a/test/Generics/function_defs.swift +++ b/test/Generics/function_defs.swift @@ -145,7 +145,6 @@ protocol IntSubscriptable { subscript (index : Int) -> ElementType { get } } -// expected-note @+1 {{mark parameter with 'var' to make it mutable}} {{66-66=var }} func subscripting>(t: T) { var index = t.getIndex() var value = t.getValue() diff --git a/test/Generics/generic_types.swift b/test/Generics/generic_types.swift index a896bb416361e..3064dbe048c67 100644 --- a/test/Generics/generic_types.swift +++ b/test/Generics/generic_types.swift @@ -66,7 +66,8 @@ struct GenericReq< T : GeneratorType, U : GeneratorType where T.Element == U.Element > {} -func getFirst(var r: R) -> R.Element { +func getFirst(r: R) -> R.Element { + var r = r return r.next()! } diff --git a/test/Generics/same_type_constraints.swift b/test/Generics/same_type_constraints.swift index 3d4427b393769..754582b618686 100644 --- a/test/Generics/same_type_constraints.swift +++ b/test/Generics/same_type_constraints.swift @@ -54,7 +54,8 @@ public struct GeneratorOf : GeneratorType, SequenceType { /// Construct an instance whose `next()` method pulls its results /// from `base`. - public init(var _ base: G) { + public init(_ base: G) { + var base = base self._next = { base.next() } } @@ -197,18 +198,22 @@ extension Something { } // rdar://problem/18120419 -func TTGenWrap(var gen: G) +func TTGenWrap(gen: G) { + var gen = gen _ = gen.next() } -func IntIntGenWrap(var gen: G) +func IntIntGenWrap(gen: G) { + var gen = gen _ = gen.next() } -func GGWrap(var g1: G1, var _ g2: G2) +func GGWrap(g1: G1, _ g2: G2) { + var g1 = g1 + var g2 = g2 _ = g1.next() _ = g2.next() } diff --git a/test/IDE/print_ast_tc_decls.swift b/test/IDE/print_ast_tc_decls.swift index c4a49a825e9d6..8e08ea915b65a 100644 --- a/test/IDE/print_ast_tc_decls.swift +++ b/test/IDE/print_ast_tc_decls.swift @@ -126,7 +126,11 @@ struct d0100_FooStruct { func instanceFunc2(a: Int, inout b: Double) {} // PASS_COMMON-NEXT: {{^}} func instanceFunc2(a: Int, inout b: Double){{$}} - func instanceFunc3(var a: Int, let b: Double) { a = 1} + func instanceFunc3(a: Int, b: Double) { + var a = a + a = 1 + _ = a + } // PASS_COMMON-NEXT: {{^}} func instanceFunc3(a: Int, b: Double){{$}} func instanceFuncWithDefaultArg1(a: Int = 0) {} diff --git a/test/Parse/pointer_conversion.swift b/test/Parse/pointer_conversion.swift index 621686e6bd0fe..c038323a53e1e 100644 --- a/test/Parse/pointer_conversion.swift +++ b/test/Parse/pointer_conversion.swift @@ -143,7 +143,8 @@ takesConstVoidPointer([0.0, 1.0, 2.0]) // expected-error {{cannot convert value _ = x } -func stringArguments(var s: String) { +func stringArguments(s: String) { + var s = s takesConstVoidPointer(s) takesConstInt8Pointer(s) takesConstUInt8Pointer(s) @@ -201,13 +202,15 @@ func pointerInClosure(f: UnsafeMutablePointer -> Int) -> Int { struct NotEquatable {} -func arrayComparison(var x: [NotEquatable], y: [NotEquatable], p: UnsafeMutablePointer) { +func arrayComparison(x: [NotEquatable], y: [NotEquatable], p: UnsafeMutablePointer) { + var x = x // Don't allow implicit array-to-pointer conversions in operators. let a: Bool = x == y // expected-error{{binary operator '==' cannot be applied to two '[NotEquatable]' operands}} let _: Bool = p == &x // Allowed! } -func addressConversion(p: UnsafeMutablePointer, var x: Int) { +func addressConversion(p: UnsafeMutablePointer, x: Int) { + var x = x let _: Bool = p == &x } diff --git a/test/SILGen/statements.swift b/test/SILGen/statements.swift index 603b2754b64af..4cfdc52c65bc8 100644 --- a/test/SILGen/statements.swift +++ b/test/SILGen/statements.swift @@ -23,10 +23,13 @@ func abort() { abort() } -func assignment(var x: Int, var y: Int) { +func assignment(x: Int, y: Int) { + var x = x + var y = y x = 42 y = 57 - + _ = x + _ = y (x, y) = (1,2) } @@ -152,7 +155,8 @@ func do_loop_with_continue(x: Int, y: Bool, z: Bool) -> Int { // CHECK-LABEL: sil hidden @{{.*}}for_loops1 -func for_loops1(var x: Int, c: Bool) { +func for_loops1(x: Int, c: Bool) { + var x = x for i in 1..<100 { markUsed(i) } @@ -507,7 +511,8 @@ func defer_in_generic(x: T) { } // CHECK-LABEL: sil hidden @_TF10statements13defer_mutableFSiT_ -func defer_mutable(var x: Int) { +func defer_mutable(x: Int) { + var x = x // CHECK: [[BOX:%.*]] = alloc_box $Int // CHECK-NOT: [[BOX]]#0 // CHECK: function_ref @_TFF10statements13defer_mutableFSiT_L_6$deferfT_T_ : $@convention(thin) (@inout Int) -> () diff --git a/test/SILGen/writeback_conflict_diagnostics.swift b/test/SILGen/writeback_conflict_diagnostics.swift index 8eb9a9884403f..12dcfb1d579c3 100644 --- a/test/SILGen/writeback_conflict_diagnostics.swift +++ b/test/SILGen/writeback_conflict_diagnostics.swift @@ -67,7 +67,8 @@ func testComputedStructWithProperty() { var global_array : [[Int]] -func testMultiArray(i : Int, j : Int, var array : [[Int]]) { +func testMultiArray(i : Int, j : Int, array : [[Int]]) { + var array = array swap(&array[i][j], &array[i][i]) swap(&array[0][j], @@ -93,8 +94,9 @@ struct ArrayWithoutAddressors { var global_array_without_addressors: ArrayWithoutAddressors> func testMultiArrayWithoutAddressors( - i: Int, j: Int, var array: ArrayWithoutAddressors> + i: Int, j: Int, array: ArrayWithoutAddressors> ) { + var array = array swap(&array[i][j], // expected-note {{concurrent writeback occurred here}} &array[i][i]) // expected-error {{inout writeback through subscript occurs in multiple arguments to call, introducing invalid aliasing}} swap(&array[0][j], // expected-note {{concurrent writeback occurred here}} diff --git a/test/SILPasses/mandatory_inlining.swift b/test/SILPasses/mandatory_inlining.swift index 308b1e47e5b28..682f649ea79d9 100644 --- a/test/SILPasses/mandatory_inlining.swift +++ b/test/SILPasses/mandatory_inlining.swift @@ -158,7 +158,7 @@ func testInlineUnionElement() -> X { @transparent -func call_let_auto_closure(@autoclosure let x: () -> Bool) -> Bool { +func call_let_auto_closure(@autoclosure x: () -> Bool) -> Bool { return x() } @@ -167,7 +167,7 @@ func call_let_auto_closure(@autoclosure let x: () -> Bool) -> Bool { // CHECK-NEXT: debug_value %0 : $Bool // CHECK-NEXT: return %0 : $Bool -func test_let_auto_closure_with_value_capture(let x: Bool) -> Bool { +func test_let_auto_closure_with_value_capture(x: Bool) -> Bool { return call_let_auto_closure(x) } diff --git a/test/SILPasses/switch.swift b/test/SILPasses/switch.swift index f9df795b37431..187c5e38d2b0f 100644 --- a/test/SILPasses/switch.swift +++ b/test/SILPasses/switch.swift @@ -1,6 +1,7 @@ // RUN: %target-swift-frontend -emit-sil %s -verify -func non_fully_covered_switch(var x: Int) -> Int { +func non_fully_covered_switch(x: Int) -> Int { + var x = x switch x { case 0: x++ diff --git a/test/Sema/accessibility_multi.swift b/test/Sema/accessibility_multi.swift index b264e5b4dca95..953a83dd6bfd0 100644 --- a/test/Sema/accessibility_multi.swift +++ b/test/Sema/accessibility_multi.swift @@ -8,13 +8,15 @@ func testGlobals() { reset(&privateSetGlobal) // expected-error {{cannot pass immutable value as inout argument: 'privateSetGlobal' setter is inaccessible}} } -func testProperties(var instance: Members) { +func testProperties(instance: Members) { + var instance = instance read(instance.privateSetProp) instance.privateSetProp = 42 // expected-error {{cannot assign to property: 'privateSetProp' setter is inaccessible}} reset(&instance.privateSetProp) // expected-error {{cannot pass immutable value as inout argument: 'privateSetProp' setter is inaccessible}} } -func testSubscript(var instance: Members) { +func testSubscript(instance: Members) { + var instance = instance read(instance[]) instance[] = 42 // expected-error {{cannot assign through subscript: subscript setter is inaccessible}} reset(&instance[]) // expected-error {{cannot pass immutable value as inout argument: subscript setter is inaccessible}} diff --git a/test/Sema/immutability.swift b/test/Sema/immutability.swift index b4ab11e93d379..27bd126f8fe99 100644 --- a/test/Sema/immutability.swift +++ b/test/Sema/immutability.swift @@ -36,7 +36,7 @@ func passClosure() { return 42 } - takeClosure { (a : Int) -> Int in // expected-note {{mark parameter with 'var' to make it mutable}} {{18-18=var }} + takeClosure { (a : Int) -> Int in a = 42 // expected-error{{cannot assign to value: 'a' is a 'let' constant}} return 42 } @@ -220,9 +220,9 @@ func test_mutability() { } -func test_arguments(a : Int, // expected-note {{mark parameter with 'var' to make it mutable}} {{21-21=var }} - var b : Int, - let c : Int) { // expected-note {{change 'let' parameter to 'var' to make it mutable}} {{21-24=var}} +func test_arguments(a : Int, + var b : Int, // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{21-25=}} + let c : Int) { // expected-warning {{Use of 'let' binding here is deprecated and will be removed in a future version of Swift}} {{21-25=}} a = 1 // expected-error {{cannot assign to value: 'a' is a 'let' constant}} b = 2 // ok. c = 3 // expected-error {{cannot assign to value: 'c' is a 'let' constant}} @@ -310,16 +310,18 @@ protocol SubscriptNoGetter { subscript (i: Int) -> Int { get } } -func testSubscriptNoGetter(let iis: SubscriptNoGetter) { +func testSubscriptNoGetter(iis: SubscriptNoGetter) { var _: Int = iis[17] } -func testSelectorStyleArguments1(var x: Int, var bar y: Int) { +func testSelectorStyleArguments1(x: Int, bar y: Int) { + var x = x + var y = y ++x; ++y } -func testSelectorStyleArguments2(let x: Int, // expected-note {{change 'let' parameter to 'var' to make it mutable}} {{34-37=var}} - let bar y: Int) { // expected-note {{change 'let' parameter to 'var' to make it}} {{34-37=var}} +func testSelectorStyleArguments2(x: Int, + bar y: Int) { ++x // expected-error {{cannot pass immutable value to mutating operator: 'x' is a 'let' constant}} ++y // expected-error {{cannot pass immutable value to mutating operator: 'y' is a 'let' constant}} } @@ -427,9 +429,9 @@ struct StructWithDelegatingInit { -func test_recovery_missing_name_1(var: Int) {} // expected-error 2{{expected ',' separator}} {{38-38=,}} {{38-38=,}} expected-error 2{{expected parameter type following ':'}} +func test_recovery_missing_name_1(: Int) {} // expected-error {{expected ',' separator}} {{35-35=,}} expected-error {{expected parameter type following ':'}} -func test_recovery_missing_name_2(let: Int) {} // expected-error 2{{expected ',' separator}} {{38-38=,}} {{38-38=,}} expected-error 2{{expected parameter type following ':'}} +func test_recovery_missing_name_2(: Int) {} // expected-error {{expected ',' separator}} {{35-35=,}} expected-error {{expected parameter type following ':'}} // compiler infinite loops on a really really mutating function @@ -485,7 +487,7 @@ struct TestSubscriptMutability { } } -func f(a : TestSubscriptMutability) { // expected-note {{mark parameter with 'var' to make it mutable}} {{8-8=var }} +func f(a : TestSubscriptMutability) { a.var_arr = [] // expected-error {{cannot assign to property: 'a' is a 'let' constant}} } diff --git a/test/attr/attr_autoclosure.swift b/test/attr/attr_autoclosure.swift index 480b88c2bf592..0460d3b50bece 100644 --- a/test/attr/attr_autoclosure.swift +++ b/test/attr/attr_autoclosure.swift @@ -12,7 +12,7 @@ func func2(@autoclosure fp : () -> Int) { func2(4)} func func3(@autoclosure fp fpx : () -> Int) {func3(fp: 0)} func func4(@autoclosure fp fp : () -> Int) {func4(fp: 0)} -func func5(@autoclosure var fp fp : () -> Int) {func5(fp: 0)} // expected-warning {{parameter 'fp' was never mutated}} {{25-29=}} +func func5(@autoclosure fp fp : () -> Int) {func5(fp: 0)} func func6(@autoclosure _: () -> Int) {func6(0)} // declattr and typeattr on the argument. diff --git a/test/attr/attr_objc.swift b/test/attr/attr_objc.swift index fb401786bc5e0..57fe706fd853c 100644 --- a/test/attr/attr_objc.swift +++ b/test/attr/attr_objc.swift @@ -718,11 +718,13 @@ class infer_instanceFunc1 { // expected-error@-1 {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}} // expected-note@-2 {{Swift structs cannot be represented in Objective-C}} - @objc func func_varParam1(var a: AnyObject) { + @objc func func_varParam1(a: AnyObject) { + var a = a let b = a; a = b } - func func_varParam2(var a: AnyObject) { + func func_varParam2(a: AnyObject) { + var a = a let b = a; a = b } // CHECK-LABEL: @objc func func_varParam2(a: AnyObject) { diff --git a/test/attr/attr_warn_unused_result.swift b/test/attr/attr_warn_unused_result.swift index 6e20f5c63b2a4..86e48ab4b03a2 100644 --- a/test/attr/attr_warn_unused_result.swift +++ b/test/attr/attr_warn_unused_result.swift @@ -69,7 +69,8 @@ struct Mutating1 { mutating func barInPlace(x: Int, y: Int) { } } -func testMutating1(m1: Mutating1, var m2: Mutating1) { +func testMutating1(m1: Mutating1, m2: Mutating1) { + var m2 = m2 m1.foo() // expected-warning{{result of call to 'foo()' is unused}} m2.foo() // expected-warning{{result of call to non-mutating function 'foo()' is unused; use 'fooInPlace()' to mutate in-place}}{{6-9=fooInPlace}} diff --git a/test/decl/class/override.swift b/test/decl/class/override.swift index c1a6582b152fa..04eb470d8a70f 100644 --- a/test/decl/class/override.swift +++ b/test/decl/class/override.swift @@ -144,13 +144,13 @@ class H : G { func oneA(_: AnyObject) {} func oneB(x x: AnyObject) {} - func oneC(var x x: AnyObject) {} // expected-warning {{parameter 'x' was never mutated}} {{13-16=}} + func oneC(x x: AnyObject) {} func oneD(x: AnyObject) {} func manyA(_: AnyObject, _: AnyObject) {} func manyB(a: AnyObject, b: AnyObject) {} - func manyC(var a: AnyObject, // expected-warning {{parameter 'a' was never mutated}} {{14-17=}} - var b: AnyObject) {} // expected-warning {{parameter 'b' was never mutated}} {{14-18=}} + func manyC(a: AnyObject, + b: AnyObject) {} func result() -> AnyObject? { return nil } func both(x: AnyObject) -> AnyObject? { return x } @@ -167,9 +167,9 @@ class IUOTestSubclass : IUOTestBaseClass { override func oneB(x x: AnyObject!) {} // expected-warning {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}} // expected-note@-1 {{remove '!' to make the parameter required}} {{36-37=}} // expected-note@-2 {{add parentheses to silence this warning}} {{27-27=(}} {{37-37=)}} - override func oneC(var x x: AnyObject!) {} // expected-warning {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}} expected-warning {{parameter 'x' was never mutated}} {{22-25=}} - // expected-note@-1 {{remove '!' to make the parameter required}} {{40-41=}} - // expected-note@-2 {{add parentheses to silence this warning}} {{31-31=(}} {{41-41=)}} + override func oneC(x x: AnyObject!) {} // expected-warning {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}} + // expected-note@-1 {{remove '!' to make the parameter required}} {{36-37=}} + // expected-note@-2 {{add parentheses to silence this warning}} {{27-27=(}} {{37-37=)}} override func oneD(x: AnyObject!) {} // expected-warning {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}} // expected-note@-1 {{remove '!' to make the parameter required}} {{34-35=}} // expected-note@-2 {{add parentheses to silence this warning}} {{25-25=(}} {{35-35=)}} @@ -180,7 +180,7 @@ class IUOTestSubclass : IUOTestBaseClass { override func manyB(a: AnyObject!, b: AnyObject!) {} // expected-warning 2 {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}} // expected-note@-1 2 {{remove '!' to make the parameter required}} // expected-note@-2 2 {{add parentheses to silence this warning}} - override func manyC(var a: AnyObject!, var b: AnyObject!) {} // expected-warning 2 {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}} expected-warning {{parameter 'a' was never mutated}} {{23-26=}} expected-warning {{parameter 'b' was never mutated}} {{42-46=}} + override func manyC(a: AnyObject!, b: AnyObject!) {} // expected-warning 2 {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}} // expected-note@-1 2 {{remove '!' to make the parameter required}} // expected-note@-2 2 {{add parentheses to silence this warning}} @@ -206,9 +206,9 @@ class IUOTestSubclass2 : IUOTestBaseClass { override func oneA(x: AnyObject!) {} // expected-warning {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}} // expected-note@-1 {{remove '!' to make the parameter required}} {{34-35=}} // expected-note@-2 {{add parentheses to silence this warning}} {{25-25=(}} {{35-35=)}} - override func oneB(var x x: AnyObject!) {} // expected-warning {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}} expected-warning {{parameter 'x' was never mutated}} {{22-25=}} - // expected-note@-1 {{remove '!' to make the parameter required}} {{40-41=}} - // expected-note@-2 {{add parentheses to silence this warning}} {{31-31=(}} {{41-41=)}} + override func oneB(x x: AnyObject!) {} // expected-warning {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}} + // expected-note@-1 {{remove '!' to make the parameter required}} {{36-37=}} + // expected-note@-2 {{add parentheses to silence this warning}} {{27-27=(}} {{37-37=)}} override func oneD(_: AnyObject!) {} // expected-warning {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}} // expected-note@-1 {{remove '!' to make the parameter required}} {{34-35=}} // expected-note@-2 {{add parentheses to silence this warning}} {{25-25=(}} {{35-35=)}} diff --git a/test/decl/ext/protocol.swift b/test/decl/ext/protocol.swift index 3ab9ef3c8b527..9fa5d0c5d1048 100644 --- a/test/decl/ext/protocol.swift +++ b/test/decl/ext/protocol.swift @@ -141,8 +141,10 @@ struct SubscriptC1 : SubscriptP1 { func writeAt(i: Int, string: String) { } } -func testSubscriptP1(var ss1: SubscriptS1, var sc1: SubscriptC1, +func testSubscriptP1(ss1: SubscriptS1, sc1: SubscriptC1, i: Int, s: String) { + var ss1 = ss1 + var sc1 = sc1 _ = ss1[i] ss1[i] = s diff --git a/test/decl/func/dynamic_self.swift b/test/decl/func/dynamic_self.swift index c6a6e40c2010a..397ada2128cf5 100644 --- a/test/decl/func/dynamic_self.swift +++ b/test/decl/func/dynamic_self.swift @@ -211,7 +211,8 @@ protocol P { func f() -> Self } -func testGenericCall(var t: T) { +func testGenericCall(t: T) { + var t = t var t2 = t.f() t2 = t t = t2 @@ -229,7 +230,8 @@ func testExistentialCall(p: P) { @objc func method() -> Self { return self } } -func testAnyObject(var ao: AnyObject) { +func testAnyObject(ao: AnyObject) { + var ao = ao var result : AnyObject = ao.method!() result = ao ao = result diff --git a/test/decl/func/functions.swift b/test/decl/func/functions.swift index eec772d9131c8..233b7f65c46a1 100644 --- a/test/decl/func/functions.swift +++ b/test/decl/func/functions.swift @@ -121,7 +121,7 @@ func testObjCMethodCurry(a : ClassWithObjCMethod) -> (Int) -> () { } // We used to crash on this. -func rdar16786220(var let c: Int) -> () { // expected-error {{parameter may not have multiple 'inout', 'var', or 'let' specifiers}} {{23-27=}} +func rdar16786220(var let c: Int) -> () { // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{19-22=}} expected-error {{parameter may not have multiple 'inout', 'var', or 'let' specifiers}} c = 42 } @@ -135,8 +135,11 @@ func !!!(lhs: UnsafePointer, rhs: UnsafePointer) -> Bool { return false // Functions currently permit 'var inout' parameters -func var_inout_error(inout var x : Int) {} // expected-error {{parameter may not have multiple 'inout', 'var', or 'let' specifiers}} {{28-32=}} -func var_inout_error(var inout x : Int) {} // expected-error {{parameter may not have multiple 'inout', 'var', or 'let' specifiers}} {{26-32=}} expected-warning {{parameter 'x' was never mutated}} {{22-25=}} +func inout_inout_error(inout inout x : Int) {} // expected-error {{parameter may not have multiple 'inout', 'var', or 'let' specifiers}} {{30-36=}} +// expected-warning@+1 {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{22-25=}} +func var_inout_error(var inout x : Int) { // expected-error {{parameter may not have multiple 'inout', 'var', or 'let' specifiers}} {{26-32=}} + x = 2 +} // Unnamed parameters require the name "_": func unnamed(Int) { } // expected-error{{unnamed parameters must be written with the empty name '_'}}{{14-14=_: }} diff --git a/test/decl/func/trailing_closures.swift b/test/decl/func/trailing_closures.swift index c20c6c822978b..e718a0c238ba7 100644 --- a/test/decl/func/trailing_closures.swift +++ b/test/decl/func/trailing_closures.swift @@ -5,7 +5,7 @@ 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}} {{9-12=}} +func f4(f: (() -> ())?, bar: Int = 10) { } // expected-warning{{closure parameter prior to parameters with default arguments will not be treated as a trailing closure}} // An extra set of parentheses suppresses the warning. func g1(f: (() -> ()), bar: Int = 10) { } // no-warning diff --git a/test/decl/inherit/initializer.swift b/test/decl/inherit/initializer.swift index f8d274852acab..db1dc930f923d 100644 --- a/test/decl/inherit/initializer.swift +++ b/test/decl/inherit/initializer.swift @@ -95,8 +95,8 @@ class SuperUnnamed { init(int _: Int) { } init(_ : Double) { } - init(var string _: String) { } - init(var _ : Float) { } + init(string _: String) { } + init(_ : Float) { } } class SubUnnamed : SuperUnnamed { } diff --git a/test/decl/var/usage.swift b/test/decl/var/usage.swift index 6fe6ba3289878..e1c1acdffab2f 100644 --- a/test/decl/var/usage.swift +++ b/test/decl/var/usage.swift @@ -12,8 +12,11 @@ func basicTests() -> Int { return y } -func mutableParameter(a : Int, h : Int, var i : Int, var j: Int, - var g : Int) -> Int { // expected-warning {{parameter 'g' was never mutated; consider changing to 'let' constant}} {{8-12=}} +// expected-warning@+2 {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{41-45=}} +// expected-warning@+1 {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{54-58=}} +func mutableParameter(a : Int, h : Int, var i : Int, var j: Int, + var g : Int) -> Int { // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{8-12=}} + g += 1 swap(&i, &j) return i+g } @@ -97,7 +100,7 @@ func testSubscript() -> [Int] { } -func testTuple(var x : Int) -> Int { +func testTuple(var x : Int) -> Int { // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{16-19=}} var y : Int // Ok, stored by a tuple (x, y) = (1,2) @@ -160,8 +163,8 @@ protocol Fooable { mutating func mutFoo() func immutFoo() } -func testOpenExistential(var x: Fooable, - var y: Fooable) { // expected-warning {{parameter 'y' was never mutated; consider changing to 'let' constant}} {{26-30=}} +func testOpenExistential(var x: Fooable, // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{26-29=}} + y: Fooable) { x.mutFoo() y.immutFoo() } diff --git a/test/expr/cast/bridged.swift b/test/expr/cast/bridged.swift index d8700822c1b4e..b7af4615e9512 100644 --- a/test/expr/cast/bridged.swift +++ b/test/expr/cast/bridged.swift @@ -75,7 +75,9 @@ func testBridgeDowncastExact(obj: BridgedClass, objOpt: BridgedClass?, _ = objImplicitOpt as? BridgedStruct // expected-warning{{conditional cast from 'BridgedClass!' to 'BridgedStruct' always succeeds}} } -func testExplicitBridging(var object: BridgedClass, var value: BridgedStruct) { +func testExplicitBridging(object: BridgedClass, value: BridgedStruct) { + var object = object + var value = value object = value as BridgedClass value = object as BridgedStruct } diff --git a/test/expr/closure/closures.swift b/test/expr/closure/closures.swift index 6a040d9acf390..73d865baf836d 100644 --- a/test/expr/closure/closures.swift +++ b/test/expr/closure/closures.swift @@ -158,11 +158,10 @@ class ExplicitSelfRequiredTest { } } - -// rdar://16393849 - 'var' and 'let' should be usable in closure argument lists. +// expected-warning@+2 {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{57-60=}} +// expected-warning@+1 {{Use of 'let' binding here is deprecated and will be removed in a future version of Swift}} {{64-68=}} var testClosureArgumentPatterns: (Int, Int) -> Int = { (var x, let y) in x+y+1 } - class SomeClass { var field : SomeClass? func foo() -> Int {} diff --git a/test/expr/expressions.swift b/test/expr/expressions.swift index 405845318b8c9..f5784a895b36c 100644 --- a/test/expr/expressions.swift +++ b/test/expr/expressions.swift @@ -788,6 +788,6 @@ func r22348394() { // Compiler crashes in Assertion failed: ((AllowOverwrite || !E->hasLValueAccessKind()) && "l-value access kind has already been set"), function visit protocol P { var y: String? { get } } -func r23185177(var x: P?) -> [String] { // expected-warning{{parameter 'x' was never mutated}} +func r23185177(x: P?) -> [String] { return x?.y // expected-error{{cannot convert return expression of type 'String?' to return type '[String]'}} } diff --git a/test/expr/postfix/call/construction.swift b/test/expr/postfix/call/construction.swift index 11adfc6a06522..a4bf6dc5e1e17 100644 --- a/test/expr/postfix/call/construction.swift +++ b/test/expr/postfix/call/construction.swift @@ -66,7 +66,8 @@ protocol P { init() } -func constructArchetypeValue(var t: T, tm: T.Type) { +func constructArchetypeValue(t: T, tm: T.Type) { + var t = t var t1 = T() t = t1 t1 = t