Skip to content

Commit a51f98e

Browse files
committed
[Exclusivity] Add a small number of static end-to-end tests.
These encode the most common forms of violation we expect to detect statically. This is a test-only change.
1 parent ae3b13e commit a51f98e

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

test/SILOptimizer/exclusivity_static_diagnostics.swift

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import Swift
44

5-
func takesTwoInouts(_ p1: inout Int, _ p2: inout Int) { }
5+
func takesTwoInouts<T>(_ p1: inout T, _ p2: inout T) { }
66

77
func simpleInoutDiagnostic() {
88
var i = 7
@@ -20,3 +20,37 @@ func swapNoSuppression(_ i: Int, _ j: Int) {
2020
// expected-note@+1{{conflicting modification requires exclusive access}}
2121
swap(&a[i], &a[j]) // no-warning
2222
}
23+
24+
class SomeClass { }
25+
26+
struct StructWithMutatingMethodThatTakesSelfInout {
27+
var f = SomeClass()
28+
mutating func mutate(_ other: inout StructWithMutatingMethodThatTakesSelfInout) { }
29+
mutating func mutate(_ other: inout SomeClass) { }
30+
31+
mutating func callMutatingMethodThatTakesSelfInout() {
32+
// expected-warning@+2{{modification requires exclusive access}}
33+
// expected-note@+1{{conflicting modification requires exclusive access}}
34+
mutate(&self)
35+
}
36+
37+
mutating func callMutatingMethodThatTakesSelfStoredPropInout() {
38+
// expected-warning@+2{{modification requires exclusive access}}
39+
// expected-note@+1{{conflicting modification requires exclusive access}}
40+
mutate(&self.f)
41+
}
42+
}
43+
44+
var global1 = StructWithMutatingMethodThatTakesSelfInout()
45+
func callMutatingMethodThatTakesGlobalStoredPropInout() {
46+
// expected-warning@+2{{modification requires exclusive access}}
47+
// expected-note@+1{{conflicting modification requires exclusive access}}
48+
global1.mutate(&global1.f)
49+
}
50+
51+
func violationWithGenericType<T>(_ p: T) {
52+
var local = p
53+
// expected-warning@+2{{modification requires exclusive access}}
54+
// expected-note@+1{{conflicting modification requires exclusive access}}
55+
takesTwoInouts(&local, &local)
56+
}

0 commit comments

Comments
 (0)