@@ -100,7 +100,7 @@ struct StructWithTwoStoredProp {
100
100
// Take an unsafe pointer to a stored property while accessing another stored property.
101
101
func violationWithUnsafePointer( _ s: inout StructWithTwoStoredProp ) {
102
102
withUnsafePointer ( to: & s. f1) { ( ptr) in
103
- // expected-warning @-1 {{overlapping accesses to 's.f1', but modification requires exclusive access; consider copying to a local variable}}
103
+ // expected-error @-1 {{overlapping accesses to 's.f1', but modification requires exclusive access; consider copying to a local variable}}
104
104
_ = s. f1
105
105
// expected-note@-1 {{conflicting access is here}}
106
106
}
@@ -196,6 +196,18 @@ func callsTakesInoutAndNoEscapeClosure() {
196
196
}
197
197
}
198
198
199
+ func inoutReadWriteInout( x: inout Int ) {
200
+ // expected-error@+2{{overlapping accesses to 'x', but modification requires exclusive access; consider copying to a local variable}}
201
+ // expected-note@+1{{conflicting access is here}}
202
+ takesInoutAndNoEscapeClosure ( & x, { _ = x } )
203
+ }
204
+
205
+ func inoutWriteWriteInout( x: inout Int ) {
206
+ // expected-error@+2{{overlapping accesses to 'x', but modification requires exclusive access; consider copying to a local variable}}
207
+ // expected-note@+1{{conflicting access is here}}
208
+ takesInoutAndNoEscapeClosure ( & x, { x = 42 } )
209
+ }
210
+
199
211
func callsTakesInoutAndNoEscapeClosureWithRead( ) {
200
212
var local = 5
201
213
takesInoutAndNoEscapeClosure ( & local) { // expected-error {{overlapping accesses to 'local', but modification requires exclusive access; consider copying to a local variable}}
@@ -338,7 +350,7 @@ func testReabstractionThunk(p1: inout ParameterizedStruct<Int>,
338
350
// This tests that we still detect access violations for closures passed
339
351
// using a reabstraction thunk.
340
352
p1. takesFunctionWithGenericReturnType { _ in
341
- // expected-warning @-1 {{overlapping accesses to 'p1', but modification requires exclusive access; consider copying to a local variable}}
353
+ // expected-error @-1 {{overlapping accesses to 'p1', but modification requires exclusive access; consider copying to a local variable}}
342
354
p2 = p1
343
355
// expected-note@-1 {{conflicting access is here}}
344
356
return 3
@@ -359,12 +371,21 @@ func takesEscapingBlockClosure
359
371
func testCallNoEscapeBlockClosure( ) {
360
372
var i = 7
361
373
takesNoEscapeBlockClosure ( & i) {
362
- // expected-warning @-1 {{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
374
+ // expected-error @-1 {{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
363
375
i = 7
364
376
// expected-note@-1 {{conflicting access is here}}
365
377
}
366
378
}
367
379
380
+ func testCallNoEscapeBlockClosureRead( ) {
381
+ var i = 7
382
+ takesNoEscapeBlockClosure ( & i) {
383
+ // expected-error@-1 {{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
384
+ _ = i
385
+ // expected-note@-1 {{conflicting access is here}}
386
+ }
387
+ }
388
+
368
389
func testCallEscapingBlockClosure( ) {
369
390
var i = 7
370
391
takesEscapingBlockClosure ( & i) { // no-warning
@@ -388,7 +409,7 @@ func takesInoutAndClosureWithGenericArg<T>(_ p: inout Int, _ c: (T) -> Int) { }
388
409
func callsTakesInoutAndClosureWithGenericArg( ) {
389
410
var i = 7
390
411
takesInoutAndClosureWithGenericArg ( & i) { ( p: Int ) in
391
- // expected-warning @-1 {{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
412
+ // expected-error @-1 {{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
392
413
return i + p
393
414
// expected-note@-1 {{conflicting access is here}}
394
415
}
@@ -399,12 +420,25 @@ func callsTakesInoutAndClosureTakingNonOptionalWithClosureTakingOptional() {
399
420
var i = 7
400
421
// Test for the thunk converting an (Int?) -> () to an (Int) -> ()
401
422
takesInoutAndClosureTakingNonOptional ( & i) { ( p: Int ? ) in
402
- // expected-warning @-1 {{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
423
+ // expected-error @-1 {{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
403
424
i = 8
404
425
// expected-note@-1 {{conflicting access is here}}
405
426
}
406
427
}
407
428
429
+ // Helper.
430
+ func doOne( _ f: ( ) -> ( ) ) {
431
+ f ( )
432
+ }
433
+
434
+ func noEscapeBlock( ) {
435
+ var x = 3
436
+ doOne {
437
+ // expected-error@+2{{overlapping accesses to 'x', but modification requires exclusive access; consider copying to a local variable}}
438
+ // expected-note@+1{{conflicting access is here}}
439
+ takesInoutAndNoEscapeClosure ( & x, { _ = x } )
440
+ }
441
+ }
408
442
409
443
func inoutSeparateStructStoredProperties( ) {
410
444
var s = StructWithTwoStoredProp ( )
0 commit comments