Skip to content

Commit 6545a00

Browse files
authored
Merge pull request #81785 from gottesmm/pr-1489f56770ad7e22ae73fd5f1bdcc702edabba19
[region-isolation] Add a test showing that we do not infer nonisolated(unsafe) onto named closures.
2 parents 31b6ae2 + 359eeec commit 6545a00

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/Concurrency/transfernonsendable_nonisolatedunsafe.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,4 +1026,18 @@ func closureTests() async {
10261026
// expected-note @-1 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}}
10271027
Task.detached { _ = x4a; _ = x4b } // expected-note {{access can happen concurrently}}
10281028
}
1029+
1030+
// The reason why this works is that we do not infer nonisolated(unsafe)
1031+
// passed the begin_borrow [var_decl] of y. So we think the closure is
1032+
// nonisolated(unsafe), but its uses via the begin_borrow [var_decl] is
1033+
// not.
1034+
func testNamedClosure() async {
1035+
nonisolated(unsafe) let x = NonSendableKlass()
1036+
let y = {
1037+
_ = x
1038+
}
1039+
sendingClosure(y) // expected-warning {{sending 'y' risks causing data races}}
1040+
// expected-note @-1 {{'y' used after being passed as a 'sending' parameter}}
1041+
sendingClosure(y) // expected-note {{access can happen concurrently}}
1042+
}
10291043
}

0 commit comments

Comments
 (0)