Skip to content

Commit fc9887f

Browse files
committed
Merge pull request #281 from divadretlaw/master
Removed the ++ and -- operators
2 parents 12e670a + 8849aa3 commit fc9887f

File tree

10 files changed

+30
-27
lines changed

10 files changed

+30
-27
lines changed

test/IDE/complete_stmt_controlling_expr.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func testCStyleForBodyI5(fooObject: FooStruct) {
378378
func testCStyleForBodyI6(fooObject: FooStruct) {
379379
var localInt = 42
380380
var localFooObject = FooStruct(localInt)
381-
for var i = 0; ; unknown_var++ {
381+
for var i = 0; ; unknown_var += 1 {
382382
#^C_STYLE_FOR_BODY_I_6^#
383383
}
384384
}

test/Interpreter/break_continue.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func test1() {
1515
func test2() {
1616
print("test2")
1717
var i : Int
18-
for i=0;i<10;i += 1 {
18+
for i in 0..<10 {
1919
if i > 2 {
2020
continue
2121
}
@@ -25,7 +25,7 @@ func test2() {
2525
func test3() {
2626
print("test3")
2727
var i : Int
28-
for i=0;i<10;i += 1 {
28+
for i in 0..<10 {
2929
if i > 2 {
3030
break
3131
}

test/Parse/recovery.swift

100644100755
File mode changed.

test/Prototypes/MutableIndexableDict.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct FixedSizedRefArrayOfOptional<T>
120120
init(capacity: Int)
121121
{
122122
buffer = Storage.Buffer(Storage.self, capacity, capacity)
123-
for var i = 0; i < capacity; ++i {
123+
for i in 0..<capacity {
124124
(buffer.baseAddress + i).initialize(.None)
125125
}
126126

@@ -181,11 +181,12 @@ struct DictionaryIndex<Element> : BidirectionalIndexType {
181181
typealias Index = DictionaryIndex<Element>
182182

183183
func predecessor() -> Index {
184-
var j = self.offset
185-
while --j > 0 {
184+
var j = self.offset - 1
185+
while j > 0 {
186186
if buffer[j] != nil {
187187
return Index(buffer: buffer, offset: j)
188188
}
189+
j -= 1
189190
}
190191
return self
191192
}
@@ -275,7 +276,7 @@ struct Dictionary<Key: Hashable, Value> : CollectionType, SequenceType {
275276
_buffer[i.offset] = Element(key: key, value: value)
276277

277278
if !found {
278-
++_count
279+
_count += 1
279280
}
280281
}
281282
}
@@ -360,7 +361,7 @@ struct Dictionary<Key: Hashable, Value> : CollectionType, SequenceType {
360361

361362
// remove the element
362363
_buffer[pos.offset] = .None
363-
--_count
364+
_count -= 1
364365

365366
// If we've put a hole in a chain of contiguous elements, some
366367
// element after the hole may belong where the new hole is.

test/SILGen/coverage_while.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ func foo() -> Int32 {
99
}
1010

1111
// CHECK: [[@LINE+1]]:9 -> [[@LINE+1]]:18 : (0 + 2)
12-
while (--x > 0) {
13-
if (x % 2 == 0) { continue }
12+
while (x > 0) {
13+
if (x % 2 == 0) { x -= 1; continue }
14+
x -= 1
1415
}
1516

1617
// CHECK: [[@LINE+1]]:9 -> [[@LINE+1]]:18 : ((0 + 4) - 5)
1718
while (x < 100) {
18-
if (x++ == 10) { break }
19+
if (x == 10) { break }
20+
x += 1
1921
}
2022

2123
// CHECK: [[@LINE+1]]:9 -> [[@LINE+1]]:18 : ((0 + 6) - 9)

test/SILGen/sil_locations.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
func ifexpr() -> Int {
66
var x : Int = 0
77
if true {
8-
x++;
8+
x += 1;
99
}
1010
return x
1111
// CHECK-LABEL: sil hidden @_TF13sil_locations6ifexprFT_Si
@@ -18,9 +18,9 @@ func ifexpr() -> Int {
1818
func ifelseexpr() -> Int {
1919
var x : Int = 0
2020
if true {
21-
x++;
21+
x += 1;
2222
} else {
23-
x--;
23+
x -= 1;
2424
}
2525
return x
2626
// CHECK-LABEL: sil hidden @_TF13sil_locations10ifelseexprFT_Si
@@ -64,7 +64,7 @@ func ifexpr_rval() -> Int {
6464

6565
// TODO: missing info on the first branch.
6666
func forstmt_empty_cond(i: Int) -> Int {
67-
for var i=0;;++i {}
67+
for var i=0;; i += 1 {}
6868
// CHECK-LABEL: sil hidden @{{.*}}forstmt_empty_cond{{.*}}
6969
// CHECK: apply {{.*}} line:[[@LINE-2]]:13
7070
// CHECK: br [[TRUE_BB:bb[0-9]+]]
@@ -116,7 +116,7 @@ func multipleReturnsImplicitAndExplicit() {
116116
if x > 10 {
117117
return
118118
}
119-
x++;
119+
x += 1;
120120
// CHECK-LABEL: sil hidden @_TF13sil_locations34multipleReturnsImplicitAndExplicitFT_T_
121121
// CHECK: cond_br
122122
// CHECK: br bb{{[0-9]+}} // {{.*}} line:[[@LINE-5]]:5:return
@@ -175,13 +175,13 @@ func testIf() {
175175
}
176176

177177
func testFor() {
178-
for (var i:Int = 0; i<10; i++) {
178+
for i in 0..<10 {
179179
var y: Int = 300
180-
y++;
180+
y += 1;
181181
if true {
182182
break
183183
}
184-
y--;
184+
y -= 1;
185185
continue
186186
}
187187

@@ -352,7 +352,7 @@ func testStringForEachStmt() {
352352
func testForStmt() {
353353
var i = 0
354354
var m = 0
355-
for (i = 0; i < 10; ++i) {
355+
for i in 0..<10 {
356356
m += 1
357357
if m == 15 {
358358
break

test/Sema/immutability.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func let_decls() {
9595

9696

9797
let e = 42 // expected-note {{change 'let' to 'var' to make it mutable}} {{3-6=var}}
98-
++e // expected-error {{cannot pass immutable value to mutating operator: 'e' is a 'let' constant}}
98+
e += 1 // expected-error {{cannot pass immutable value to mutating operator: 'e' is a 'let' constant}}
9999

100100
// <rdar://problem/16306600> QoI: passing a 'let' value as an inout results in an unfriendly diagnostic
101101
let f = 96 // expected-note {{change 'let' to 'var' to make it mutable}} {{3-6=var}}
@@ -322,8 +322,8 @@ func testSelectorStyleArguments1(x: Int, bar y: Int) {
322322

323323
func testSelectorStyleArguments2(x: Int,
324324
bar y: Int) {
325-
++x // expected-error {{cannot pass immutable value to mutating operator: 'x' is a 'let' constant}}
326-
++y // expected-error {{cannot pass immutable value to mutating operator: 'y' is a 'let' constant}}
325+
x += 1 // expected-error {{cannot pass immutable value to mutating operator: 'x' is a 'let' constant}}
326+
y += 1 // expected-error {{cannot pass immutable value to mutating operator: 'y' is a 'let' constant}}
327327
}
328328

329329
func invalid_inout(inout var x : Int) { // expected-error {{parameter may not have multiple 'inout', 'var', or 'let' specifiers}} {{26-30=}}

test/SourceKit/DocumentStructure/Inputs/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var (sd2: Qtys)
7373
}
7474

7575
for i in 0...5 {}
76-
for var i = 0, i2 = 1; i == 0; ++i {}
76+
for var i = 0, i2 = 1; i == 0; i += 1 {}
7777
while let v = o, z = o where v > z {}
7878
repeat {} while v == 0
7979
if let v = o, z = o where v > z {}

test/SourceKit/Indexing/index.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ func test1(cp: ComputedProperty, sub: CC2) {
9393
var x = cp.value
9494
x = cp.readOnly
9595
cp.value = x
96-
++cp.value
96+
cp.value += 1
9797
x = sub[0]
9898
sub[0] = x
99-
++sub[0]
99+
sub[0] += 1
100100
}
101101

102102
struct S2 {

validation-test/stdlib/OpenCLSDKOverlay.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ tests.test("clSetKernelArgsListAPPLE") {
243243
// Validate our results
244244
//
245245
correct = 0
246-
for(i = 0; i < count; i++)
246+
for i in 0..<count
247247
{
248248
if(results[i] == data[i] * data[i]){
249249
correct += 1

0 commit comments

Comments
 (0)