Revert "REVERTME: Temporarily make vars in refutable patterns a warning"

This reverts commit b96e06da44, making
vars in refutable patterns an error for Swift 3.

rdar://problem/23172698
This commit is contained in:
David Farler
2016-01-14 18:12:31 -08:00
parent 1d3916e6ad
commit a6f2530780
12 changed files with 48 additions and 54 deletions

View File

@@ -632,8 +632,10 @@ ERROR(untyped_pattern_ellipsis,pattern_parsing,none,
"'...' cannot be applied to a subpattern which is not explicitly typed", ())
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 '%select{var|let}0' binding here is deprecated and will be removed in a future version of Swift", (unsigned))
ERROR(var_not_allowed_in_pattern,pattern_parsing, none,
"Use of 'var' binding here is not allowed", ())
WARNING(let_on_param_is_redundant,pattern_parsing, none,
"'let' keyword is unnecessary; function parameters are immutable by default", (unsigned))
ERROR(var_pattern_in_var,pattern_parsing,none,
"'%select{var|let}0' cannot appear nested inside another 'var' or "
"'let' pattern", (unsigned))

View File

@@ -180,15 +180,15 @@ 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,
diagnose(Tok.getLoc(), diag::let_on_param_is_redundant,
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());
diagnose(Tok.getLoc(), diag::var_not_allowed_in_pattern)
.fixItRemove(Tok.getLoc());
param.LetVarInOutLoc = consumeToken();
param.SpecifierKind = ParsedParameter::Var;
param.SpecifierKind = ParsedParameter::Let;
}
// Redundant specifiers are fairly common, recognize, reject, and recover
@@ -773,7 +773,7 @@ ParserResult<Pattern> Parser::parsePattern() {
} else {
// In an always immutable context, `var` is not allowed.
if (alwaysImmutable)
diagnose(varLoc, diag::var_not_allowed_in_pattern, isLetKeyword)
diagnose(varLoc, diag::var_not_allowed_in_pattern)
.fixItRemove(varLoc);
}
@@ -978,7 +978,7 @@ ParserResult<Pattern> 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, isLet)
diagnose(varLoc, diag::var_not_allowed_in_pattern)
.fixItReplace(varLoc, "let");
// In our recursive parse, remember that we're in a var/let pattern.

View File

@@ -167,8 +167,8 @@ default: break
// FIXME: rdar://problem/23378003
// These will eventually become errors.
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=}}
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=}}
for (var x) in 0...100 {} // expected-error {{Use of 'var' binding here is not allowed}} {{6-9=}}
for var x in 0...100 {} // expected-error {{Use of 'var' binding here is not allowed}} {{5-9=}}
for (let x) in 0...100 {} // expected-error {{'let' pattern is already in an immutable context}}

View File

@@ -38,7 +38,7 @@ func foo() -> Int {
}
}
func goo(var e : ErrorType) {}
func goo(e : ErrorType) {}
struct Test1 : OptionSetType {
init(rawValue: Int) {}

View File

@@ -35,7 +35,5 @@ func for_each(r: Range<Int>, iir: IntRange<Int>) {
for i in r sum = sum + i; // expected-error{{expected '{' to start the body of for-each loop}}
for let x in 0..<10 {} // expected-error {{'let' pattern is already in an immutable context}} {{7-11=}}
// FIXME: rdar://problem/23378003
// This will eventually become an error.
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=}}
for var x in 0..<10 {} // expected-error {{Use of 'var' binding here is not allowed}} {{7-11=}}
}

View File

@@ -32,11 +32,9 @@ case let (let b): // expected-error {{'let' cannot appear nested inside another
print(b)
// 'var' patterns (not allowed)
// FIXME: rdar://problem/23378003
// This will eventually be an error.
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}}
case var a: // expected-error {{Use of 'var' binding here is not allowed}} {{6-9=let}}
a += 1
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}}
case var let a: // expected-error {{Use of 'var' binding here is not allowed}} {{6-9=let}}
// expected-error@-1 {{'let' cannot appear nested inside another 'var' or 'let' pattern}}
print(a, terminator: "")

View File

@@ -216,9 +216,9 @@ case (1, let b): // let bindings
// var bindings are not allowed in cases.
// FIXME: rdar://problem/23378003
// This will eventually be an error.
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}}
case (1, var b): // expected-error {{Use of 'var' binding here is not allowed}} {{10-13=let}}
()
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}}
case (var a, 2): // expected-error {{Use of 'var' binding here is not allowed}} {{7-10=let}}
()
case (let a, 2), (1, let b): // expected-error {{'case' labels with multiple patterns cannot declare variables}}

View File

@@ -221,10 +221,10 @@ func test_mutability() {
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=}}
var b : Int, // expected-error {{Use of 'var' binding here is not allowed}} {{21-25=}}
let c : Int) { // expected-warning {{'let' keyword is unnecessary; function parameters are immutable by default}} {{21-25=}}
a = 1 // expected-error {{cannot assign to value: 'a' is a 'let' constant}}
b = 2 // ok.
var b = 2 // ok.
c = 3 // expected-error {{cannot assign to value: 'c' is a 'let' constant}}
}

View File

@@ -146,7 +146,7 @@ public class SubscriptCursorTest {
// 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
// CHECK12: source.lang.swift.decl.var.local (28:23-28:27)
// CHECK12: <Declaration>var arg1: <Type usr="s:Si">Int</Type></Declaration>
// CHECK12: <Declaration>let arg1: <Type usr="s:Si">Int</Type></Declaration>
// 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
// CHECK13: source.lang.swift.decl.function.free (31:6-31:37)

View File

@@ -121,8 +121,10 @@ func testObjCMethodCurry(a : ClassWithObjCMethod) -> (Int) -> () {
}
// We used to crash on this.
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}}
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}}
var c = c
c = 42
_ = c
}
@@ -136,9 +138,11 @@ func !!!<T>(lhs: UnsafePointer<T>, rhs: UnsafePointer<T>) -> Bool { return false
// <rdar://problem/16786168> Functions currently permit 'var inout' parameters
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=}}
// expected-error@+1 {{Use of 'var' binding here is not allowed}} {{22-25=}}
func var_inout_error(var inout x : Int) { // expected-error {{parameter may not have multiple 'inout', 'var', or 'let' specifiers}} {{26-32=}}
var x = x
x = 2
_ = x
}
// Unnamed parameters require the name "_":

View File

@@ -12,11 +12,13 @@ func basicTests() -> Int {
return y
}
// 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=}}
// expected-error@+2 {{Use of 'var' binding here is not allowed}} {{41-45=}}
// expected-error@+1 {{Use of 'var' binding here is not allowed}} {{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=}}
var g : Int) -> Int { // expected-error {{Use of 'var' binding here is not allowed}} {{8-12=}}
// expected-error@+1 {{left side of mutating operator isn't mutable: 'g' is a 'let' constant}}
g += 1
// expected-error@+1 {{cannot pass immutable value as inout argument: 'i' is a 'let' constant}}
swap(&i, &j)
return i+g
}
@@ -100,9 +102,10 @@ func testSubscript() -> [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=}}
func testTuple(var x : Int) -> Int { // expected-error {{Use of 'var' binding here is not allowed}} {{16-19=}}
var y : Int // Ok, stored by a tuple
// expected-error@+1 {{cannot assign to value: 'x' is a 'let' constant}}
(x, y) = (1,2)
return y
}
@@ -163,8 +166,9 @@ protocol Fooable {
mutating func mutFoo()
func immutFoo()
}
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=}}
func testOpenExistential(var x: Fooable, // expected-error {{Use of 'var' binding here is not allowed}} {{26-29=}}
y: Fooable) {
// expected-error@+1 {{cannot use mutating member on immutable value}}
x.mutFoo()
y.immutFoo()
}
@@ -173,10 +177,8 @@ func testOpenExistential(var x: Fooable, // expected-warning {{Use of 'var' bind
func couldThrow() throws {}
func testFixitsInStatementsWithPatterns(a : Int?) {
// FIXME: rdar://problem/23378003
// This will eventually be an error.
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}}
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}}
if var b = a, // expected-error {{Use of 'var' binding here is not allowed}} {{6-9=let}}
var b2 = a { // expected-error {{Use of 'var' binding here is not allowed}} {{7-10=let}}
b = 1
b2 = 1
_ = b
@@ -184,24 +186,18 @@ func testFixitsInStatementsWithPatterns(a : Int?) {
}
var g = [1,2,3].generate()
// FIXME: rdar://problem/23378003
// This will eventually be an error.
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}}
while var x = g.next() { // expected-error {{Use of 'var' binding here is not allowed}} {{9-12=let}}
x = 0
_ = x
}
// FIXME: rdar://problem/23378003
// This will eventually be an error.
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}}
guard var y = Optional.Some(1) else { // expected-error {{Use of 'var' binding here is not allowed}} {{9-12=let}}
return
}
y = 0
_ = y
// FIXME: rdar://problem/23378003
// This will eventually be an error.
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=}}
for var b in [42] { // expected-error {{Use of 'var' binding here is not allowed}} {{7-11=}}
b = 42
_ = b
}
@@ -212,18 +208,14 @@ func testFixitsInStatementsWithPatterns(a : Int?) {
do {
try couldThrow()
// FIXME: rdar://problem/23378003
// This will eventually be an error.
} 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}}
} catch var err { // expected-error {{Use of 'var' binding here is not allowed}} {{11-14=let}}
// expected-warning@-1 {{variable 'err' was never mutated; consider changing to 'let' constant}}
_ = err
}
switch a {
// FIXME: rdar://problem/23378003
// This will eventually be an error.
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}}
// expected-warning@-1 {{variable 'b' was never mutated; consider changing to 'let' constant}}
case var b: // expected-error {{Use of 'var' binding here is not allowed}} {{10-13=let}}
// expected-warning@-1 {{was never mutated; consider changing to 'let' constant}}
_ = b
}
}

View File

@@ -157,8 +157,8 @@ class ExplicitSelfRequiredTest {
}
}
// 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=}}
// expected-error@+2 {{Use of 'var' binding here is not allowed}} {{57-60=}}
// expected-warning@+1 {{'let' keyword is unnecessary; function parameters are immutable by default}} {{64-68=}}
var testClosureArgumentPatterns: (Int, Int) -> Int = { (var x, let y) in x+y+1 }
class SomeClass {