Skip to content

Commit 0224f2d

Browse files
committed
Convert more tests off of ++ and --
1 parent 82e5c0c commit 0224f2d

10 files changed

+55
-119
lines changed

test/Parse/optional_chain_lvalues.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mutT?.mutateT()
2525
immT?.mutateT() // expected-error{{cannot use mutating member on immutable value: 'immT' is a 'let' constant}}
2626
mutT?.mutS?.mutateS()
2727
mutT?.immS?.mutateS() // expected-error{{cannot use mutating member on immutable value: 'immS' is a 'let' constant}}
28-
mutT?.mutS?.x++
28+
mutT?.mutS?.x += 1
2929
mutT?.mutS?.y++ // expected-error{{cannot pass immutable value to mutating operator: 'y' is a 'let' constant}}
3030

3131
// Prefix operators don't chain

test/SILGen/statements.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func for_loops1(x: Int, c: Bool) {
166166
x += 1
167167
}
168168

169-
for var i = 0; i < 100; ++i { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
169+
for var i = 0; i < 100; i += 1 { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
170170
}
171171

172172
for let i = 0; i < 100; i { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}

test/SILGen/unreachable_code.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,36 @@ func testUnreachableAfterIfReturn(a: Bool) -> Int {
1616
}
1717

1818
func testUnreachableForAfterContinue(b: Bool) {
19-
for (var i:Int = 0; i<10; i++) { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
19+
for (var i:Int = 0; i<10; i+=1) { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
2020
var y: Int = 300
21-
y++;
21+
y += 1
2222
if b {
2323
break
24-
y++; // expected-warning {{code after 'break' will never be executed}}
24+
y += 1 // expected-warning {{code after 'break' will never be executed}}
2525
}
2626
continue
27-
y--; // expected-warning {{code after 'continue' will never be executed}}
27+
y -= 1 // expected-warning {{code after 'continue' will never be executed}}
2828
}
2929
}
3030

3131
func testUnreachableWhileAfterContinue(b: Bool) {
3232
var i:Int = 0
3333
while (i<10) {
3434
var y: Int = 300
35-
y++;
35+
y += 1
3636
if b {
3737
break
38-
y++; // expected-warning {{code after 'break' will never be executed}}
38+
y += 1 // expected-warning {{code after 'break' will never be executed}}
3939
}
4040
continue
41-
i++; // expected-warning {{code after 'continue' will never be executed}}
41+
i += 1 // expected-warning {{code after 'continue' will never be executed}}
4242
}
4343
}
4444

4545
func testBreakAndContinue() {
4646
var i = 0
4747
var m = 0
48-
for (i = 0; i < 10; ++i) { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
48+
for (i = 0; i < 10; i += 1) { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
4949
m += 1
5050
if m == 15 {
5151
break

test/SILOptimizer/definite_init_diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ struct StructMutatingMethodTest {
10461046
let y : Int
10471047
init() {
10481048
x = 42
1049-
++x // expected-error {{mutating operator '++' may not be used on immutable value 'self.x'}}
1049+
x += 1 // expected-error {{mutating operator '+=' may not be used on immutable value 'self.x'}}
10501050

10511051
y = 12
10521052
myTransparentFunction(&y) // expected-error {{immutable value 'self.y' may not be passed inout}}

test/SILOptimizer/diagnostic_constant_propagation.swift

Lines changed: 20 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -242,130 +242,66 @@ func testDivision() {
242242

243243
func testPostIncOverflow() {
244244
var s_max = Int.max
245-
s_max++ // expected-error {{arithmetic operation '9223372036854775807 + 1' (on signed 64-bit integer type) results in an overflow}}
245+
s_max += 1 // expected-error {{arithmetic operation '9223372036854775807 + 1' (on type 'Int') results in an overflow}}
246246

247247
var u_max = UInt.max
248-
u_max++ // expected-error {{arithmetic operation '18446744073709551615 + 1' (on unsigned 64-bit integer type) results in an overflow}}
248+
u_max += 1 // expected-error {{arithmetic operation '18446744073709551615 + 1' (on type 'UInt') results in an overflow}}
249249

250250
var s8_max = Int8.max
251-
s8_max++ // expected-error {{arithmetic operation '127 + 1' (on signed 8-bit integer type) results in an overflow}}
251+
s8_max += 1 // expected-error {{arithmetic operation '127 + 1' (on type 'Int8') results in an overflow}}
252252

253253
var u8_max = UInt8.max
254-
u8_max++ // expected-error {{arithmetic operation '255 + 1' (on unsigned 8-bit integer type) results in an overflow}}
254+
u8_max += 1 // expected-error {{arithmetic operation '255 + 1' (on type 'UInt8') results in an overflow}}
255255

256256
var s16_max = Int16.max
257-
s16_max++ // expected-error {{arithmetic operation '32767 + 1' (on signed 16-bit integer type) results in an overflow}}
257+
s16_max += 1 // expected-error {{arithmetic operation '32767 + 1' (on type 'Int16') results in an overflow}}
258258

259259
var u16_max = UInt16.max
260-
u16_max++ // expected-error {{arithmetic operation '65535 + 1' (on unsigned 16-bit integer type) results in an overflow}}
260+
u16_max += 1 // expected-error {{arithmetic operation '65535 + 1' (on type 'UInt16') results in an overflow}}
261261

262262
var s32_max = Int32.max
263-
s32_max++ // expected-error {{arithmetic operation '2147483647 + 1' (on signed 32-bit integer type) results in an overflow}}
263+
s32_max += 1 // expected-error {{arithmetic operation '2147483647 + 1' (on type 'Int32') results in an overflow}}
264264

265265
var u32_max = UInt32.max
266-
u32_max++ // expected-error {{arithmetic operation '4294967295 + 1' (on unsigned 32-bit integer type) results in an overflow}}
266+
u32_max += 1 // expected-error {{arithmetic operation '4294967295 + 1' (on type 'UInt32') results in an overflow}}
267267

268268
var s64_max = Int64.max
269-
s64_max++ // expected-error {{arithmetic operation '9223372036854775807 + 1' (on signed 64-bit integer type) results in an overflow}}
269+
s64_max += 1 // expected-error {{arithmetic operation '9223372036854775807 + 1' (on type 'Int64') results in an overflow}}
270270

271271
var u64_max = UInt64.max
272-
u64_max++ // expected-error {{arithmetic operation '18446744073709551615 + 1' (on unsigned 64-bit integer type) results in an overflow}}
273-
}
274-
275-
func testPreIncOverflow() {
276-
var s_max = Int.max
277-
++s_max // expected-error {{arithmetic operation '9223372036854775807 + 1' (on signed 64-bit integer type) results in an overflow}}
278-
279-
var u_max = UInt.max
280-
++u_max // expected-error {{arithmetic operation '18446744073709551615 + 1' (on unsigned 64-bit integer type) results in an overflow}}
281-
282-
var s8_max = Int8.max
283-
++s8_max // expected-error {{arithmetic operation '127 + 1' (on signed 8-bit integer type) results in an overflow}}
284-
285-
var u8_max = UInt8.max
286-
++u8_max // expected-error {{arithmetic operation '255 + 1' (on unsigned 8-bit integer type) results in an overflow}}
287-
288-
var s16_max = Int16.max
289-
++s16_max // expected-error {{arithmetic operation '32767 + 1' (on signed 16-bit integer type) results in an overflow}}
290-
291-
var u16_max = UInt16.max
292-
++u16_max // expected-error {{arithmetic operation '65535 + 1' (on unsigned 16-bit integer type) results in an overflow}}
293-
294-
var s32_max = Int32.max
295-
++s32_max // expected-error {{arithmetic operation '2147483647 + 1' (on signed 32-bit integer type) results in an overflow}}
296-
297-
var u32_max = UInt32.max
298-
++u32_max // expected-error {{arithmetic operation '4294967295 + 1' (on unsigned 32-bit integer type) results in an overflow}}
299-
300-
var s64_max = Int64.max
301-
++s64_max // expected-error {{arithmetic operation '9223372036854775807 + 1' (on signed 64-bit integer type) results in an overflow}}
302-
303-
var u64_max = UInt64.max
304-
++u64_max // expected-error {{arithmetic operation '18446744073709551615 + 1' (on unsigned 64-bit integer type) results in an overflow}}
272+
u64_max += 1 // expected-error {{arithmetic operation '18446744073709551615 + 1' (on type 'UInt64') results in an overflow}}
305273
}
306274

307275
func testPostDecOverflow() {
308276
var s_min = Int.min
309-
s_min-- // expected-error {{arithmetic operation '-9223372036854775808 - 1' (on signed 64-bit integer type) results in an overflow}}
310-
311-
var u_min = UInt.min
312-
u_min-- // expected-error {{arithmetic operation '0 - 1' (on unsigned 64-bit integer type) results in an overflow}}
313-
314-
var s8_min = Int8.min
315-
s8_min-- // expected-error {{arithmetic operation '-128 - 1' (on signed 8-bit integer type) results in an overflow}}
316-
317-
var u8_min = UInt8.min
318-
u8_min-- // expected-error {{arithmetic operation '0 - 1' (on unsigned 8-bit integer type) results in an overflow}}
319-
320-
var s16_min = Int16.min
321-
s16_min-- // expected-error {{arithmetic operation '-32768 - 1' (on signed 16-bit integer type) results in an overflow}}
322-
323-
var u16_min = UInt16.min
324-
u16_min-- // expected-error {{arithmetic operation '0 - 1' (on unsigned 16-bit integer type) results in an overflow}}
325-
326-
var s32_min = Int32.min
327-
s32_min-- // expected-error {{arithmetic operation '-2147483648 - 1' (on signed 32-bit integer type) results in an overflow}}
328-
329-
var u32_min = UInt32.min
330-
u32_min-- // expected-error {{arithmetic operation '0 - 1' (on unsigned 32-bit integer type) results in an overflow}}
331-
332-
var s64_min = Int64.min
333-
s64_min-- // expected-error {{arithmetic operation '-9223372036854775808 - 1' (on signed 64-bit integer type) results in an overflow}}
334-
335-
var u64_min = UInt64.min
336-
u64_min-- // expected-error {{arithmetic operation '0 - 1' (on unsigned 64-bit integer type) results in an overflow}}
337-
}
338-
339-
func testPreDecOverflow() {
340-
var s_min = Int.min
341-
--s_min // expected-error {{arithmetic operation '-9223372036854775808 - 1' (on signed 64-bit integer type) results in an overflow}}
277+
s_min -= 1 // expected-error {{arithmetic operation '-9223372036854775808 - 1' (on type 'Int') results in an overflow}}
342278

343279
var u_min = UInt.min
344-
--u_min // expected-error {{arithmetic operation '0 - 1' (on unsigned 64-bit integer type) results in an overflow}}
280+
u_min -= 1 // expected-error {{arithmetic operation '0 - 1' (on type 'UInt') results in an overflow}}
345281

346282
var s8_min = Int8.min
347-
--s8_min // expected-error {{arithmetic operation '-128 - 1' (on signed 8-bit integer type) results in an overflow}}
283+
s8_min -= 1 // expected-error {{arithmetic operation '-128 - 1' (on type 'Int8') results in an overflow}}
348284

349285
var u8_min = UInt8.min
350-
--u8_min // expected-error {{arithmetic operation '0 - 1' (on unsigned 8-bit integer type) results in an overflow}}
286+
u8_min -= 1 // expected-error {{arithmetic operation '0 - 1' (on type 'UInt8') results in an overflow}}
351287

352288
var s16_min = Int16.min
353-
--s16_min // expected-error {{arithmetic operation '-32768 - 1' (on signed 16-bit integer type) results in an overflow}}
289+
s16_min -= 1 // expected-error {{arithmetic operation '-32768 - 1' (on type 'Int16') results in an overflow}}
354290

355291
var u16_min = UInt16.min
356-
--u16_min // expected-error {{arithmetic operation '0 - 1' (on unsigned 16-bit integer type) results in an overflow}}
292+
u16_min -= 1 // expected-error {{arithmetic operation '0 - 1' (on type 'UInt16') results in an overflow}}
357293

358294
var s32_min = Int32.min
359-
--s32_min // expected-error {{arithmetic operation '-2147483648 - 1' (on signed 32-bit integer type) results in an overflow}}
295+
s32_min -= 1 // expected-error {{arithmetic operation '-2147483648 - 1' (on type 'Int32') results in an overflow}}
360296

361297
var u32_min = UInt32.min
362-
--u32_min // expected-error {{arithmetic operation '0 - 1' (on unsigned 32-bit integer type) results in an overflow}}
298+
u32_min -= 1 // expected-error {{arithmetic operation '0 - 1' (on type 'UInt32') results in an overflow}}
363299

364300
var s64_min = Int64.min
365-
--s64_min // expected-error {{arithmetic operation '-9223372036854775808 - 1' (on signed 64-bit integer type) results in an overflow}}
301+
s64_min -= 1 // expected-error {{arithmetic operation '-9223372036854775808 - 1' (on type 'Int64') results in an overflow}}
366302

367303
var u64_min = UInt64.min
368-
--u64_min // expected-error {{arithmetic operation '0 - 1' (on unsigned 64-bit integer type) results in an overflow}}
304+
u64_min -= 1 // expected-error {{arithmetic operation '0 - 1' (on type 'UInt64') results in an overflow}}
369305
}
370306

371307
func testAssumeNonNegative() {

test/SILOptimizer/return.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func multipleBlocksSingleMissing(b: Bool) -> (String, Int) {
2525
func multipleBlocksAllMissing(x: Int) -> Int {
2626
var y : Int = x + 1
2727
while (y > 0 ) {
28-
--y
28+
y -= 1
2929
break
3030
}
3131
var x = 0
@@ -81,7 +81,7 @@ func whileLoop(flag: Bool) -> Int {
8181
if b == 3 {
8282
return 3
8383
}
84-
b++
84+
b += 1
8585
}
8686
} //expected-error {{missing return in a function expected to return 'Int'}}
8787

@@ -91,7 +91,7 @@ func whileTrueLoop() -> Int {
9191
if b == 3 {
9292
return 3
9393
}
94-
b++
94+
b += 1
9595
} // no-error
9696
}
9797

test/SILOptimizer/unreachable_code.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func whileTrueReachable(v: Int) -> () {
4040
}
4141
x += 1
4242
}
43-
x--
43+
x -= 1
4444
}
4545

4646
func whileTrueTwoPredecessorsEliminated() -> () {
@@ -119,9 +119,9 @@ func testSwitchEnum(xi: Int) -> Int {
119119
case .One:
120120
userCode() // expected-note {{will never be executed}}
121121
case .Two:
122-
x--
122+
x -= 1
123123
case .Three:
124-
x--
124+
x -= 1
125125
}
126126

127127
switch cond { // no warning
@@ -221,7 +221,7 @@ func testSwitchOptionalBool (b:Bool?, xi: Int) -> Int {
221221
case .Some(true):
222222
x += 1
223223
case .None:
224-
x--
224+
x -= 1
225225
} // expected-error{{switch must be exhaustive}}
226226

227227
return xi

test/Sema/immutability.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func testSubscriptNoGetter(iis: SubscriptNoGetter) {
317317
func testSelectorStyleArguments1(x: Int, bar y: Int) {
318318
var x = x
319319
var y = y
320-
++x; ++y
320+
x += 1; y += 1
321321
}
322322

323323
func testSelectorStyleArguments2(x: Int,

test/expr/closure/closures.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ class ExplicitSelfRequiredTest {
136136
var x = 42
137137
func method() -> Int {
138138
// explicit closure requires an explicit "self." base.
139-
doStuff({ ++self.x })
140-
doStuff({ ++x }) // expected-error {{reference to property 'x' in closure requires explicit 'self.' to make capture semantics explicit}} {{17-17=self.}}
141-
doVoidStuff({ ++x }) // expected-error {{reference to property 'x' in closure requires explicit 'self.' to make capture semantics explicit}} {{21-21=self.}}
139+
doVoidStuff({ self.x += 1 })
140+
doStuff({ x+1 }) // expected-error {{reference to property 'x' in closure requires explicit 'self.' to make capture semantics explicit}} {{15-15=self.}}
141+
doVoidStuff({ x += 1 }) // expected-error {{reference to property 'x' in closure requires explicit 'self.' to make capture semantics explicit}} {{19-19=self.}}
142142

143143
// Methods follow the same rules as properties, uses of 'self' must be marked with "self."
144144
doStuff { method() } // expected-error {{call to method 'method' in closure requires explicit 'self.' to make capture semantics explicit}} {{15-15=self.}}

test/stmt/statements.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,22 @@ SomeGeneric<Int>
121121
func for_loop() {
122122
var x = 0
123123
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}}
124+
for x = 1; x != 42; x += 1 { } // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
125125
for infloopbooltest(); x != 12; infloopbooltest() {} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
126126

127127
for ; { } // expected-error {{expected ';' in 'for' statement}}
128128

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}}
129+
for var y = 1; y != 42; y += 1 {} // 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 += 1) {} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
131131
var z = 10
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}}
132+
for (; z != 0; z -= 1) {} // 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 -= 1) {} // 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 -= 1 {a += 1} // 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 -= 1) {a += 1} // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
136136
var j, k : Int
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}}
137+
for ((j,k) = (0,10); j != k; k -= 1) {} // 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 += 1, j += 1 {} // 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 += 1, k -= 1 { } // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
140140
// rdar://19540536
141141
// expected-error@+4{{expected var declaration in a 'for' statement}}
142142
// expected-error@+3{{expression resolves to an unused function}}
@@ -187,7 +187,7 @@ func tuple_assign() {
187187
func missing_semicolons() {
188188
var w = 321
189189
func g() {}
190-
g() ++w // expected-error{{consecutive statements}} {{6-6=;}}
190+
g() w += 1 // expected-error{{consecutive statements}} {{6-6=;}}
191191
var z = w"hello" // expected-error{{consecutive statements}} {{12-12=;}}
192192
class C {}class C2 {} // expected-error{{consecutive statements}} {{14-14=;}}
193193
struct S {}struct S2 {} // expected-error{{consecutive statements}} {{14-14=;}}
@@ -427,12 +427,12 @@ func testThrowNil() throws {
427427
func for_ignored_lvalue_init() {
428428
var i = 0
429429
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-
i < 10; ++i {}
430+
i < 10; i += 1 {}
431431
}
432432

433433
// rdar://problem/18643692
434434
func for_loop_multi_iter() {
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}}
435+
for (var i = 0, x = 0; i < 10; i += 1, // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
436436
x) { // expected-error {{expression resolves to an unused l-value}}
437437
x -= 1
438438
}

0 commit comments

Comments
 (0)