Skip to content

Commit 626bae7

Browse files
committed
[Concurrency] Add a test case for passing a non-Sendable argument to a
nonisolated closure in an actor-isolated context. (cherry picked from commit 9b16d47)
1 parent f15f1a8 commit 626bae7

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

test/Concurrency/sendable_checking.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func testConversionsAndSendable(a: MyActor, s: any Sendable, f: @Sendable () ->
249249
final class NonSendable {
250250
// expected-note @-1 3 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
251251
// SendNonSendable emits 3 fewer errors here.
252-
// expected-targeted-and-complete-note @-3 3 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
252+
// expected-targeted-and-complete-note @-3 4 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
253253
var value = ""
254254

255255
@MainActor
@@ -284,3 +284,15 @@ func testNonSendableBaseArg() async {
284284
_ = await t.x
285285
// expected-warning @-1 {{non-sendable type 'NonSendable' passed in implicitly asynchronous call to main actor-isolated property 'x' cannot cross actor boundary}}
286286
}
287+
288+
@available(SwiftStdlib 5.1, *)
289+
@MainActor
290+
func callNonisolatedAsyncClosure(
291+
ns: NonSendable,
292+
g: (NonSendable) async -> Void
293+
) async {
294+
// FIXME: This should also produce a diagnostic with SendNonSendable, because
295+
// the 'ns' parameter should be merged into the MainActor's region.
296+
await g(ns)
297+
// expected-targeted-and-complete-warning@-1 {{passing argument of non-sendable type 'NonSendable' outside of main actor-isolated context may introduce data races}}
298+
}

0 commit comments

Comments
 (0)