2
2
3
3
import Swift
4
4
5
- func takesTwoInouts( _ p1: inout Int , _ p2: inout Int ) { }
5
+ func takesTwoInouts< T > ( _ p1: inout T , _ p2: inout T ) { }
6
6
7
7
func simpleInoutDiagnostic( ) {
8
8
var i = 7
@@ -20,3 +20,37 @@ func swapNoSuppression(_ i: Int, _ j: Int) {
20
20
// expected-note@+1{{conflicting modification requires exclusive access}}
21
21
swap ( & a[ i] , & a[ j] ) // no-warning
22
22
}
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