Skip to content

Commit 3403bb6

Browse files
authored
Merge pull request #18745 from atrick/test-conditional-noescape
Add a test case for a type checker deficiency.
2 parents 6d467fd + 3837574 commit 3403bb6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

test/SILOptimizer/exclusivity_static_diagnostics.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,11 @@ struct S {
606606
// expected-error@-1 2 {{overlapping accesses to 'self', but modification requires exclusive access; consider copying to a local variable}}
607607
}
608608
}
609+
610+
// TODO: A conflict should also be detected here. However, the
611+
// typechecker does not allow it. Enable the following test if we ever
612+
// remove this case from the typechecker test:
613+
// diag_invalid_inout_captures.swift.
614+
// public func nestedConflict(x: inout Int) {
615+
// doit(x: &x, x == 0 ? { x = 1 } : { x = 2})
616+
// }

test/Sema/diag_invalid_inout_captures.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ func remember(line: inout String) -> () -> Void {
3333
return despite_our_estrangement // expected-error {{nested function cannot capture inout parameter and escape}}
3434
}
3535

36+
// This arrangement should be legal, but the type checker does not currently allow it.
37+
//
38+
// TODO: If the type checker is ever fixed, we should enable the corresponding test in
39+
// SILOptimizer/exclusivity_static_diagnostics.swift.
40+
func its_complicated(condition: inout Int) {
41+
no_escape(condition == 0 ? { condition = 1 } : { condition = 2}) // expected-error 2 {{escaping closures can only capture inout parameters explicitly by value}}
42+
}

0 commit comments

Comments
 (0)