Skip to content

Commit f44df2f

Browse files
authored
Merge pull request #4965 from jrose-apple/swift-3-where-no-comma-has-gone-before
[Parse] 'where' to ',' fix-it should remove a preceding space.
2 parents 9a5ea12 + 0621559 commit f44df2f

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

lib/Parse/ParseStmt.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,17 +1179,17 @@ ParserStatus Parser::parseStmtCondition(StmtCondition &Condition,
11791179
if (Tok.isAny(tok::oper_binary_spaced, tok::oper_binary_unspaced) &&
11801180
Tok.getText() == "&&") {
11811181
diagnose(Tok, diag::expected_comma_stmtcondition)
1182-
.fixItReplace(Tok.getLoc(), ",");
1182+
.fixItReplaceChars(getEndOfPreviousLoc(), Tok.getRange().getEnd(), ",");
11831183
consumeToken();
11841184
return true;
11851185
}
11861186

11871187
// Boolean conditions are separated by commas, not the 'where' keyword, as
11881188
// they were in Swift 2 and earlier.
1189-
SourceLoc whereLoc;
1190-
if (consumeIf(tok::kw_where, whereLoc)) {
1191-
diagnose(whereLoc, diag::expected_comma_stmtcondition)
1192-
.fixItReplace(whereLoc, ",");
1189+
if (Tok.is(tok::kw_where)) {
1190+
diagnose(Tok, diag::expected_comma_stmtcondition)
1191+
.fixItReplaceChars(getEndOfPreviousLoc(), Tok.getRange().getEnd(), ",");
1192+
consumeToken();
11931193
return true;
11941194
}
11951195

test/Parse/availability_query.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if !#available(OSX 10.52, *) { // expected-error {{#available may only be used a
1717
if let _ = Optional(5), !#available(OSX 10.52, *) { // expected-error {{#available may only be used as condition}}
1818
}
1919

20-
if #available(OSX 10.51, *) && #available(OSX 10.52, *) { // expected-error {{expected ',' joining parts of a multi-clause condition}} {{29-31=,}}
20+
if #available(OSX 10.51, *) && #available(OSX 10.52, *) { // expected-error {{expected ',' joining parts of a multi-clause condition}} {{28-31=,}}
2121
}
2222

2323

test/Parse/recovery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ func f1() {
558558

559559
// <rdar://problem/20489838> QoI: Nonsensical error and fixit if "let" is missing between 'if let ... where' clauses
560560
func testMultiPatternConditionRecovery(x: Int?) {
561-
// expected-error@+1 {{expected ',' joining parts of a multi-clause condition}} {{16-21=,}}
561+
// expected-error@+1 {{expected ',' joining parts of a multi-clause condition}} {{15-21=,}}
562562
if let y = x where y == 0, let z = x {
563563
_ = y
564564
_ = z

test/stmt/statements.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,12 @@ func f21080671() {
427427
// <rdar://problem/24467411> QoI: Using "&& #available" should fixit to comma
428428
// https://twitter.com/radexp/status/694561060230184960
429429
func f(_ x : Int, y : Int) {
430-
if x == y && #available(iOS 52, *) {} // expected-error {{expected ',' joining parts of a multi-clause condition}} {{13-15=,}}
431-
if #available(iOS 52, *) && x == y {} // expected-error {{expected ',' joining parts of a multi-clause condition}} {{28-30=,}}
430+
if x == y && #available(iOS 52, *) {} // expected-error {{expected ',' joining parts of a multi-clause condition}} {{12-15=,}}
431+
if #available(iOS 52, *) && x == y {} // expected-error {{expected ',' joining parts of a multi-clause condition}} {{27-30=,}}
432432

433433
// https://twitter.com/radexp/status/694790631881883648
434-
if x == y && let _ = Optional(y) {} // expected-error {{expected ',' joining parts of a multi-clause condition}} {{13-15=,}}
434+
if x == y && let _ = Optional(y) {} // expected-error {{expected ',' joining parts of a multi-clause condition}} {{12-15=,}}
435+
if x == y&&let _ = Optional(y) {} // expected-error {{expected ',' joining parts of a multi-clause condition}} {{12-14=,}}
435436
}
436437

437438

0 commit comments

Comments
 (0)