Files
swift-mirror/test/SILOptimizer/inout_capture_diagnostics.swift
Andrew Trick 4575525786 NFC: Cleanup ClosureScope/AccessEnforcementSelection/Tests.
Per Devin and John's review.
2017-06-20 14:57:56 -07:00

29 lines
1003 B
Swift

// RUN: %target-swift-frontend -enforce-exclusivity=checked -Onone -emit-sil -swift-version 4 -verify -parse-as-library %s
//
// This is an adjunct to access_enforcement_noescape.swift to cover early static diagnostics.
// Helper
func doOneInout(_: ()->(), _: inout Int) {}
// Error: Cannot capture nonescaping closure.
// expected-note@+1{{parameter 'fn' is implicitly non-escaping}}
func reentrantCapturedNoescape(fn: (() -> ()) -> ()) {
// expected-error@+1{{closure use of non-escaping parameter 'fn' may allow it to escape}}
let c = { fn {} }
fn(c)
}
// Error: inout cannot be captured.
func inoutReadBoxWriteInout(x: inout Int) {
// expected-error@+1{{escaping closures can only capture inout parameters explicitly by value}}
let c = { _ = x }
doOneInout(c, &x)
}
// Error: Cannot capture inout
func inoutWriteBoxWriteInout(x: inout Int) {
// expected-error@+1{{escaping closures can only capture inout parameters explicitly by value}}
let c = { x = 42 }
doOneInout(c, &x)
}