Skip to content

Commit a6f2530

Browse files
committed
Revert "REVERTME: Temporarily make vars in refutable patterns a warning"
This reverts commit b96e06d, making vars in refutable patterns an error for Swift 3. rdar://problem/23172698
1 parent 1d3916e commit a6f2530

File tree

12 files changed

+48
-54
lines changed

12 files changed

+48
-54
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,10 @@ ERROR(untyped_pattern_ellipsis,pattern_parsing,none,
632632
"'...' cannot be applied to a subpattern which is not explicitly typed", ())
633633
ERROR(non_func_decl_pattern_init,pattern_parsing,none,
634634
"default argument is only permitted for a non-curried function parameter",())
635-
WARNING(var_not_allowed_in_pattern,pattern_parsing, none,
636-
"Use of '%select{var|let}0' binding here is deprecated and will be removed in a future version of Swift", (unsigned))
635+
ERROR(var_not_allowed_in_pattern,pattern_parsing, none,
636+
"Use of 'var' binding here is not allowed", ())
637+
WARNING(let_on_param_is_redundant,pattern_parsing, none,
638+
"'let' keyword is unnecessary; function parameters are immutable by default", (unsigned))
637639
ERROR(var_pattern_in_var,pattern_parsing,none,
638640
"'%select{var|let}0' cannot appear nested inside another 'var' or "
639641
"'let' pattern", (unsigned))

lib/Parse/ParsePattern.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
180180
param.LetVarInOutLoc = consumeToken();
181181
param.SpecifierKind = ParsedParameter::InOut;
182182
} else if (Tok.is(tok::kw_let)) {
183-
diagnose(Tok.getLoc(), diag::var_not_allowed_in_pattern,
183+
diagnose(Tok.getLoc(), diag::let_on_param_is_redundant,
184184
Tok.is(tok::kw_let)).fixItRemove(Tok.getLoc());
185185
param.LetVarInOutLoc = consumeToken();
186186
param.SpecifierKind = ParsedParameter::Let;
187187
} else if (Tok.is(tok::kw_var)) {
188-
diagnose(Tok.getLoc(), diag::var_not_allowed_in_pattern,
189-
Tok.is(tok::kw_let)).fixItRemove(Tok.getLoc());
188+
diagnose(Tok.getLoc(), diag::var_not_allowed_in_pattern)
189+
.fixItRemove(Tok.getLoc());
190190
param.LetVarInOutLoc = consumeToken();
191-
param.SpecifierKind = ParsedParameter::Var;
191+
param.SpecifierKind = ParsedParameter::Let;
192192
}
193193

194194
// Redundant specifiers are fairly common, recognize, reject, and recover
@@ -773,8 +773,8 @@ ParserResult<Pattern> Parser::parsePattern() {
773773
} else {
774774
// In an always immutable context, `var` is not allowed.
775775
if (alwaysImmutable)
776-
diagnose(varLoc, diag::var_not_allowed_in_pattern, isLetKeyword)
777-
.fixItRemove(varLoc);
776+
diagnose(varLoc, diag::var_not_allowed_in_pattern)
777+
.fixItRemove(varLoc);
778778
}
779779

780780
// In our recursive parse, remember that we're in a var/let pattern.
@@ -978,7 +978,7 @@ ParserResult<Pattern> Parser::parseMatchingPatternAsLetOrVar(bool isLet,
978978
diagnose(varLoc, diag::let_pattern_in_immutable_context);
979979

980980
if (!isLet && InVarOrLetPattern == IVOLP_AlwaysImmutable)
981-
diagnose(varLoc, diag::var_not_allowed_in_pattern, isLet)
981+
diagnose(varLoc, diag::var_not_allowed_in_pattern)
982982
.fixItReplace(varLoc, "let");
983983

984984
// In our recursive parse, remember that we're in a var/let pattern.

test/Constraints/patterns.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ default: break
167167

168168
// FIXME: rdar://problem/23378003
169169
// These will eventually become errors.
170-
for (var x) in 0...100 {} // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{6-9=}}
171-
for var x in 0...100 {} // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{5-9=}}
170+
for (var x) in 0...100 {} // expected-error {{Use of 'var' binding here is not allowed}} {{6-9=}}
171+
for var x in 0...100 {} // expected-error {{Use of 'var' binding here is not allowed}} {{5-9=}}
172172

173173
for (let x) in 0...100 {} // expected-error {{'let' pattern is already in an immutable context}}
174174

test/FixCode/fixits-apply.swift.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func foo() -> Int {
3838
}
3939
}
4040

41-
func goo(var e : ErrorType) {}
41+
func goo(e : ErrorType) {}
4242

4343
struct Test1 : OptionSetType {
4444
init(rawValue: Int) {}

test/Parse/foreach.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,5 @@ func for_each(r: Range<Int>, iir: IntRange<Int>) {
3535
for i in r sum = sum + i; // expected-error{{expected '{' to start the body of for-each loop}}
3636
for let x in 0..<10 {} // expected-error {{'let' pattern is already in an immutable context}} {{7-11=}}
3737

38-
// FIXME: rdar://problem/23378003
39-
// This will eventually become an error.
40-
for var x in 0..<10 {} // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{7-11=}}
38+
for var x in 0..<10 {} // expected-error {{Use of 'var' binding here is not allowed}} {{7-11=}}
4139
}

test/Parse/matching_patterns.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ case let (let b): // expected-error {{'let' cannot appear nested inside another
3232
print(b)
3333

3434
// 'var' patterns (not allowed)
35-
// FIXME: rdar://problem/23378003
36-
// This will eventually be an error.
37-
case var a: // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{6-9=let}}
35+
case var a: // expected-error {{Use of 'var' binding here is not allowed}} {{6-9=let}}
3836
a += 1
39-
case var let a: // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{6-9=let}}
37+
case var let a: // expected-error {{Use of 'var' binding here is not allowed}} {{6-9=let}}
4038
// expected-error@-1 {{'let' cannot appear nested inside another 'var' or 'let' pattern}}
4139
print(a, terminator: "")
4240

test/Parse/switch.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ case (1, let b): // let bindings
216216
// var bindings are not allowed in cases.
217217
// FIXME: rdar://problem/23378003
218218
// This will eventually be an error.
219-
case (1, var b): // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{10-13=let}}
219+
case (1, var b): // expected-error {{Use of 'var' binding here is not allowed}} {{10-13=let}}
220220
()
221-
case (var a, 2): // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{7-10=let}}
221+
case (var a, 2): // expected-error {{Use of 'var' binding here is not allowed}} {{7-10=let}}
222222
()
223223

224224
case (let a, 2), (1, let b): // expected-error {{'case' labels with multiple patterns cannot declare variables}}

test/Sema/immutability.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ func test_mutability() {
221221

222222

223223
func test_arguments(a : Int,
224-
var b : Int, // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{21-25=}}
225-
let c : Int) { // expected-warning {{Use of 'let' binding here is deprecated and will be removed in a future version of Swift}} {{21-25=}}
224+
var b : Int, // expected-error {{Use of 'var' binding here is not allowed}} {{21-25=}}
225+
let c : Int) { // expected-warning {{'let' keyword is unnecessary; function parameters are immutable by default}} {{21-25=}}
226226
a = 1 // expected-error {{cannot assign to value: 'a' is a 'let' constant}}
227-
b = 2 // ok.
227+
var b = 2 // ok.
228228
c = 3 // expected-error {{cannot assign to value: 'c' is a 'let' constant}}
229229
}
230230

test/SourceKit/SourceDocInfo/cursor_info.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public class SubscriptCursorTest {
146146

147147
// RUN: %sourcekitd-test -req=cursor -pos=28:24 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK12 %s
148148
// CHECK12: source.lang.swift.decl.var.local (28:23-28:27)
149-
// CHECK12: <Declaration>var arg1: <Type usr="s:Si">Int</Type></Declaration>
149+
// CHECK12: <Declaration>let arg1: <Type usr="s:Si">Int</Type></Declaration>
150150

151151
// RUN: %sourcekitd-test -req=cursor -pos=31:7 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK13 %s
152152
// CHECK13: source.lang.swift.decl.function.free (31:6-31:37)

test/decl/func/functions.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ func testObjCMethodCurry(a : ClassWithObjCMethod) -> (Int) -> () {
121121
}
122122

123123
// We used to crash on this.
124-
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}}
124+
func rdar16786220(var let c: Int) -> () { // expected-error {{Use of 'var' binding here is not allowed}} {{19-22=}} expected-error {{parameter may not have multiple 'inout', 'var', or 'let' specifiers}}
125+
var c = c
125126
c = 42
127+
_ = c
126128
}
127129

128130

@@ -136,9 +138,11 @@ func !!!<T>(lhs: UnsafePointer<T>, rhs: UnsafePointer<T>) -> Bool { return false
136138

137139
// <rdar://problem/16786168> Functions currently permit 'var inout' parameters
138140
func inout_inout_error(inout inout x : Int) {} // expected-error {{parameter may not have multiple 'inout', 'var', or 'let' specifiers}} {{30-36=}}
139-
// expected-warning@+1 {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{22-25=}}
141+
// expected-error@+1 {{Use of 'var' binding here is not allowed}} {{22-25=}}
140142
func var_inout_error(var inout x : Int) { // expected-error {{parameter may not have multiple 'inout', 'var', or 'let' specifiers}} {{26-32=}}
143+
var x = x
141144
x = 2
145+
_ = x
142146
}
143147

144148
// Unnamed parameters require the name "_":

test/decl/var/usage.swift

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ func basicTests() -> Int {
1212
return y
1313
}
1414

15-
// expected-warning@+2 {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{41-45=}}
16-
// expected-warning@+1 {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{54-58=}}
15+
// expected-error@+2 {{Use of 'var' binding here is not allowed}} {{41-45=}}
16+
// expected-error@+1 {{Use of 'var' binding here is not allowed}} {{54-58=}}
1717
func mutableParameter(a : Int, h : Int, var i : Int, var j: Int,
18-
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=}}
18+
var g : Int) -> Int { // expected-error {{Use of 'var' binding here is not allowed}} {{8-12=}}
19+
// expected-error@+1 {{left side of mutating operator isn't mutable: 'g' is a 'let' constant}}
1920
g += 1
21+
// expected-error@+1 {{cannot pass immutable value as inout argument: 'i' is a 'let' constant}}
2022
swap(&i, &j)
2123
return i+g
2224
}
@@ -100,9 +102,10 @@ func testSubscript() -> [Int] {
100102
}
101103

102104

103-
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=}}
105+
func testTuple(var x : Int) -> Int { // expected-error {{Use of 'var' binding here is not allowed}} {{16-19=}}
104106
var y : Int // Ok, stored by a tuple
105107

108+
// expected-error@+1 {{cannot assign to value: 'x' is a 'let' constant}}
106109
(x, y) = (1,2)
107110
return y
108111
}
@@ -163,8 +166,9 @@ protocol Fooable {
163166
mutating func mutFoo()
164167
func immutFoo()
165168
}
166-
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=}}
169+
func testOpenExistential(var x: Fooable, // expected-error {{Use of 'var' binding here is not allowed}} {{26-29=}}
167170
y: Fooable) {
171+
// expected-error@+1 {{cannot use mutating member on immutable value}}
168172
x.mutFoo()
169173
y.immutFoo()
170174
}
@@ -173,35 +177,27 @@ func testOpenExistential(var x: Fooable, // expected-warning {{Use of 'var' bind
173177
func couldThrow() throws {}
174178

175179
func testFixitsInStatementsWithPatterns(a : Int?) {
176-
// FIXME: rdar://problem/23378003
177-
// This will eventually be an error.
178-
if var b = a, // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{6-9=let}}
179-
var b2 = a { // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{7-10=let}}
180+
if var b = a, // expected-error {{Use of 'var' binding here is not allowed}} {{6-9=let}}
181+
var b2 = a { // expected-error {{Use of 'var' binding here is not allowed}} {{7-10=let}}
180182
b = 1
181183
b2 = 1
182184
_ = b
183185
_ = b2
184186
}
185187

186188
var g = [1,2,3].generate()
187-
// FIXME: rdar://problem/23378003
188-
// This will eventually be an error.
189-
while var x = g.next() { // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{9-12=let}}
189+
while var x = g.next() { // expected-error {{Use of 'var' binding here is not allowed}} {{9-12=let}}
190190
x = 0
191191
_ = x
192192
}
193193

194-
// FIXME: rdar://problem/23378003
195-
// This will eventually be an error.
196-
guard var y = Optional.Some(1) else { // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{9-12=let}}
194+
guard var y = Optional.Some(1) else { // expected-error {{Use of 'var' binding here is not allowed}} {{9-12=let}}
197195
return
198196
}
199197
y = 0
200198
_ = y
201199

202-
// FIXME: rdar://problem/23378003
203-
// This will eventually be an error.
204-
for var b in [42] { // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{7-11=}}
200+
for var b in [42] { // expected-error {{Use of 'var' binding here is not allowed}} {{7-11=}}
205201
b = 42
206202
_ = b
207203
}
@@ -212,18 +208,14 @@ func testFixitsInStatementsWithPatterns(a : Int?) {
212208

213209
do {
214210
try couldThrow()
215-
// FIXME: rdar://problem/23378003
216-
// This will eventually be an error.
217-
} catch var err { // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{11-14=let}}
211+
} catch var err { // expected-error {{Use of 'var' binding here is not allowed}} {{11-14=let}}
218212
// expected-warning@-1 {{variable 'err' was never mutated; consider changing to 'let' constant}}
219213
_ = err
220214
}
221215

222216
switch a {
223-
// FIXME: rdar://problem/23378003
224-
// This will eventually be an error.
225-
case var b: // expected-warning {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{10-13=let}}
226-
// expected-warning@-1 {{variable 'b' was never mutated; consider changing to 'let' constant}}
217+
case var b: // expected-error {{Use of 'var' binding here is not allowed}} {{10-13=let}}
218+
// expected-warning@-1 {{was never mutated; consider changing to 'let' constant}}
227219
_ = b
228220
}
229221
}

test/expr/closure/closures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class ExplicitSelfRequiredTest {
157157
}
158158
}
159159

160-
// expected-warning@+2 {{Use of 'var' binding here is deprecated and will be removed in a future version of Swift}} {{57-60=}}
161-
// expected-warning@+1 {{Use of 'let' binding here is deprecated and will be removed in a future version of Swift}} {{64-68=}}
160+
// expected-error@+2 {{Use of 'var' binding here is not allowed}} {{57-60=}}
161+
// expected-warning@+1 {{'let' keyword is unnecessary; function parameters are immutable by default}} {{64-68=}}
162162
var testClosureArgumentPatterns: (Int, Int) -> Int = { (var x, let y) in x+y+1 }
163163

164164
class SomeClass {

0 commit comments

Comments
 (0)