You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
}
5
+
6
+
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=}}
7
+
}
8
+
9
+
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=}}
10
+
}
11
+
12
+
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=}}
13
+
}
14
+
15
+
// next three aren't auto-fixable
16
+
for var e =3; e >4; e++{ // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
17
+
}
18
+
19
+
for var f =3; f <4; f--{ // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
20
+
}
21
+
22
+
letstart=Int8(4)
23
+
letcount=Int8(10)
24
+
varother=Int8(2)
25
+
26
+
for ; other<count; other++{ // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
27
+
}
28
+
29
+
// this should be fixable, and keep the type
30
+
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=}}
31
+
print(number)
32
+
}
33
+
34
+
// should produce extra note
35
+
for (var m: Int8 = start; m < count; ++m){ // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} expected-note {{C-style for statement can't be automatically fixed to for-in, because the loop variable is modified inside the loop}}
36
+
m +=3
37
+
}
38
+
39
+
// could theoretically fix this (and more like it if we auto-suggested "stride:")
40
+
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}}
41
+
}
42
+
43
+
// could theoretically fix this with "..."
44
+
for var p =2; p <=8; p++{ // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
Copy file name to clipboardExpand all lines: test/stmt/statements.swift
+15-15Lines changed: 15 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -120,23 +120,23 @@ SomeGeneric<Int>
120
120
121
121
func for_loop(){
122
122
varx=0
123
-
for ;; {}
124
-
for x =1; x !=42; ++x {}
125
-
forinfloopbooltest(); x != 12; infloopbooltest(){}
123
+
for ;; {} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
124
+
for x =1; x !=42; ++x {} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
125
+
forinfloopbooltest(); x != 12; infloopbooltest(){} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
126
126
127
127
for ; {} // expected-error {{expected ';' in 'for' statement}}
128
128
129
-
for var y =1; y !=42; ++y {}
130
-
for (var y =1; y != 42; ++y){}
129
+
for var y =1; y !=42; ++y {} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
130
+
for (var y =1; y != 42; ++y){} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
131
131
varz=10
132
-
for (; z !=0; --z){}
133
-
for (z =10; z !=0;--z){}
134
-
for var(a,b)=(0,12); a != b; --b {++a}
135
-
for (var(a,b)=(0,12); a != b; --b){++a}
132
+
for (; z !=0; --z){} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
133
+
for (z =10; z !=0;--z){} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
134
+
for var(a,b)=(0,12); a != b; --b {++a} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
135
+
for (var(a,b)=(0,12); a != b; --b){++a} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
136
136
varj,k:Int
137
-
for ((j,k)=(0,10); j != k; --k){}
138
-
for var i =0, j =0; i * j <10; i++, j++{}
139
-
for j =0, k =52; j < k; ++j,--k {}
137
+
for ((j,k)=(0,10); j != k; --k){} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
138
+
for var i =0, j =0; i * j <10; i++, j++{} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
139
+
for j =0, k =52; j < k; ++j,--k {} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
140
140
// rdar://19540536
141
141
// expected-error@+4{{expected var declaration in a 'for' statement}}
142
142
// expected-error@+3{{expression resolves to an unused function}}
@@ -145,7 +145,7 @@ func for_loop() {
145
145
for @ {}
146
146
147
147
// <rdar://problem/17462274> Is increment in for loop optional?
148
-
for (let i =0; i <10; ){}
148
+
for (let i =0; i <10; ){} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
149
149
}
150
150
151
151
break // expected-error {{'break' is only allowed inside a loop, if, do, or switch}}
for i; // expected-error {{expression resolves to an unused l-value}}
429
+
for i; // expected-error {{expression resolves to an unused l-value}} expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
430
430
i <10; ++i {}
431
431
}
432
432
433
433
// rdar://problem/18643692
434
434
func for_loop_multi_iter(){
435
-
for (var i=0, x =0; i <10; i++,
435
+
for (var i=0, x =0; i <10; i++, // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
436
436
x){ // expected-error {{expression resolves to an unused l-value}}
0 commit comments