Files
swift-mirror/test/SILOptimizer/exclusivity_static_diagnostics_swift3.swift
Devin Coughlin 6dcc8ce9b2 [Exclusivity] Don't suggest copying to a local when swapAt() is appropriate
Update static exclusivity diagnostics to not suggest copying to a local
when a call to swapAt() should be used instead. We already emit a FixIt in
this case, so don't suggest an an helpful fix in the diagnostic.

rdar://problem/32296784
2017-07-16 13:48:52 -07:00

39 lines
1.3 KiB
Swift

// RUN: %target-swift-frontend -enforce-exclusivity=checked -swift-version 3 -emit-sil -primary-file %s -o /dev/null -verify
import Swift
// In Swift 3 compatibility mode, diagnostics for exclusive accesses are
// warnings not errors.
func takesTwoInouts<T>(_ p1: inout T, _ p2: inout T) { }
func simpleInoutDiagnostic() {
var i = 7
// expected-error@+4{{inout arguments are not allowed to alias each other}}
// expected-note@+3{{previous aliasing argument}}
// expected-warning@+2{{overlapping accesses to 'i', but modification requires exclusive access; consider copying to a local variable}}
// expected-note@+1{{conflicting access is here}}
takesTwoInouts(&i, &i)
}
struct X {
var f = 12
}
func diagnoseOnSameField() {
var x = X()
// expected-warning@+2{{overlapping accesses to 'x.f', but modification requires exclusive access; consider copying to a local variable}}
// expected-note@+1{{conflicting access is here}}
takesTwoInouts(&x.f, &x.f)
}
func diagnoseSwapOnMutableCollection(_ i: Int, _ j: Int) {
var a: [Int] = [1, 2, 3]
// expected-warning@+2{{overlapping accesses to 'a', but modification requires exclusive access; consider calling MutableCollection.swapAt(_:_:)}}
// expected-note@+1{{conflicting access is here}}
swap(&a[i], &a[j])
}