Skip to content

Commit 03015c2

Browse files
committed
Merge pull request #958 from gregomni/sr-533
[SR-533] Improve C-style for fixits by also removing 'var' keyword from loop var decl.
2 parents b6b113f + e52ddaf commit 03015c2

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,7 @@ static void checkCStyleForLoop(TypeChecker &TC, const ForStmt *FS) {
18201820
SourceLoc endOfIncrementLoc = Lexer::getLocForEndOfToken(TC.Context.SourceMgr, FS->getIncrement().getPtrOrNull()->getEndLoc());
18211821

18221822
diagnostic
1823+
.fixItRemoveChars(loopVarDecl->getLoc(), loopVar->getLoc())
18231824
.fixItReplaceChars(loopPatternEnd, startValue->getStartLoc(), " in ")
18241825
.fixItReplaceChars(FS->getFirstSemicolonLoc(), endValue->getStartLoc(), " ..< ")
18251826
.fixItRemoveChars(FS->getSecondSemicolonLoc(), endOfIncrementLoc);

test/Sema/diag_c_style_for.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// RUN: %target-parse-verify-swift
22

33
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
4-
for var a = 0; a < 10; a++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{10-13= in }} {{14-20= ..< }} {{22-27=}}
4+
for var a = 0; a < 10; a++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{5-9=}} {{10-13= in }} {{14-20= ..< }} {{22-27=}}
55
}
66

77
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
8-
for var b = 0; b < 10; ++b { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{10-13= in }} {{14-20= ..< }} {{22-27=}}
8+
for var b = 0; b < 10; ++b { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{5-9=}} {{10-13= in }} {{14-20= ..< }} {{22-27=}}
99
}
1010

1111
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
12-
for var c=1;c != 5 ;++c { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{10-11= in }} {{12-18= ..< }} {{20-24=}}
12+
for var c=1;c != 5 ;++c { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{5-9=}} {{10-11= in }} {{12-18= ..< }} {{20-24=}}
1313
}
1414

1515
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
16-
for var d=100;d<5;d++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{10-11= in }} {{14-17= ..< }} {{18-22=}}
16+
for var d=100;d<5;d++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{5-9=}} {{10-11= in }} {{14-17= ..< }} {{18-22=}}
1717
}
1818

1919
// next three aren't auto-fixable
@@ -35,7 +35,7 @@ for ; other<count; other++ { // expected-warning {{C-style for statement is depr
3535

3636
// this should be fixable, and keep the type
3737
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
38-
for (var number : Int8 = start; number < count; number++) { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{23-26= in }} {{31-42= ..< }} {{47-57=}}
38+
for (var number : Int8 = start; number < count; number++) { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{6-10=}} {{23-26= in }} {{31-42= ..< }} {{47-57=}}
3939
print(number)
4040
}
4141

@@ -45,7 +45,7 @@ for (var m : Int8 = start; m < count; ++m) { // expected-warning {{C-style for s
4545
m += 3
4646
}
4747

48-
for var o = 2; o < 888; o += 1 { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{10-13= in }} {{14-20= ..< }} {{23-31=}}
48+
for var o = 2; o < 888; o += 1 { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{5-9=}} {{10-13= in }} {{14-20= ..< }} {{23-31=}}
4949
}
5050

5151
for var o = 2; o < 888; o += 11 { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}}

0 commit comments

Comments
 (0)