Skip to content

Commit aa0fd33

Browse files
committed
Exclusivity diagnostic test cases for optional closures.
Including these for completeness.
1 parent 54ebeb9 commit aa0fd33

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/SILOptimizer/exclusivity_static_diagnostics.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,28 @@ func testKeyPathWithClassFinalStoredProperty() {
527527
// model.
528528
takesTwoInouts(&local[keyPath: getI], &local[keyPath: getI])
529529
}
530+
531+
func takesInoutAndOptionalClosure(_: inout Int, _ f: (()->())?) {
532+
f!()
533+
}
534+
535+
// An optional closure is not considered @noescape:
536+
// This violation will only be caught dynamically.
537+
//
538+
// apply %takesInoutAndOptionalClosure(%closure)
539+
// : $@convention(thin) (@inout Int, @owned Optional<@callee_guaranteed () -> ()>) -> ()
540+
func testOptionalClosure() {
541+
var x = 0
542+
takesInoutAndOptionalClosure(&x) { x += 1 }
543+
}
544+
545+
func takesInoutAndOptionalBlock(_: inout Int, _ f: (@convention(block) ()->())?) {
546+
f!()
547+
}
548+
549+
// An optional block is not be considered @noescape.
550+
// This violation will only be caught dynamically.
551+
func testOptionalBlock() {
552+
var x = 0
553+
takesInoutAndOptionalBlock(&x) { x += 1 }
554+
}

0 commit comments

Comments
 (0)