Skip to content

[region-isolation] Add a test showing that we do not infer nonisolated(unsafe) onto named closures. #81785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions test/Concurrency/transfernonsendable_nonisolatedunsafe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1026,4 +1026,18 @@ func closureTests() async {
// expected-note @-1 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(priority:operation:)' risks causing races in between local and caller code}}
Task.detached { _ = x4a; _ = x4b } // expected-note {{access can happen concurrently}}
}

// The reason why this works is that we do not infer nonisolated(unsafe)
// passed the begin_borrow [var_decl] of y. So we think the closure is
// nonisolated(unsafe), but its uses via the begin_borrow [var_decl] is
// not.
func testNamedClosure() async {
nonisolated(unsafe) let x = NonSendableKlass()
let y = {
_ = x
}
sendingClosure(y) // expected-warning {{sending 'y' risks causing data races}}
// expected-note @-1 {{'y' used after being passed as a 'sending' parameter}}
sendingClosure(y) // expected-note {{access can happen concurrently}}
}
}