You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// expected-note @-2 {{'x' used after being passed as a 'sending' parameter}}
61
61
useValue(x) // expected-note {{access can happen concurrently}}
62
62
}
63
+
64
+
// Since x is returned as sending from withCheckedContinuation, we can send it
65
+
// further.
63
66
awaituseValueAsync(x)
64
-
// expected-error @-1 {{sending 'x' risks causing data races}}
65
-
// expected-note @-2 {{sending main actor-isolated 'x' to nonisolated global function 'useValueAsync' risks causing data races between nonisolated and main actor-isolated uses}}
// expected-note @-2 {{main actor-isolated 'y' is passed as a 'sending' parameter}}
89
90
useValue(y)
90
91
}
92
+
93
+
// Since withCheckedContinuation returns value as sending, we can call
94
+
// useValueAsync since it is disconnected.
91
95
awaituseValueAsync(x)
92
-
// expected-error @-1 {{sending 'x' risks causing data races}}
93
-
// expected-note @-2 {{sending main actor-isolated 'x' to nonisolated global function 'useValueAsync' risks causing data races between nonisolated and main actor-isolated uses}}
// expected-note @-2 {{'x' used after being passed as a 'sending' parameter}}
190
192
useValue(x) // expected-note {{access can happen concurrently}}
191
193
}
194
+
195
+
// withUnsafeContinuation returns x as sending, so we can pass it to a
196
+
// nonisolated function.
192
197
awaituseValueAsync(x)
193
-
// expected-error @-1 {{sending 'x' risks causing data races}}
194
-
// expected-note @-2 {{sending main actor-isolated 'x' to nonisolated global function 'useValueAsync' risks causing data races between nonisolated and main actor-isolated uses}}
// expected-note @-2 {{main actor-isolated 'y' is passed as a 'sending' parameter}}
216
219
useValue(y)
217
220
}
221
+
222
+
// Since withUnsafeContinuation returns x as sending, we can use it in a
223
+
// nonisolated function.
218
224
awaituseValueAsync(x)
219
-
// expected-error @-1 {{sending 'x' risks causing data races}}
220
-
// expected-note @-2 {{sending main actor-isolated 'x' to nonisolated global function 'useValueAsync' risks causing data races between nonisolated and main actor-isolated uses}}
Copy file name to clipboardExpand all lines: test/Concurrency/transfernonsendable_sending_results.swift
+20Lines changed: 20 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -90,6 +90,10 @@ class GenericNonSendableKlass<T> {
90
90
91
91
func sendParameter<T>(_ t:sending T){}
92
92
93
+
actorMyActor{
94
+
privatevarns=NonSendableKlass()
95
+
}
96
+
93
97
/////////////////
94
98
// MARK: Tests //
95
99
/////////////////
@@ -295,3 +299,19 @@ func indirectSendingOptionalClassField<T>(_ t: GenericNonSendableKlass<T>) -> se
295
299
// expected-note @-1 {{returning a task-isolated 'Optional<T>' value risks causing races since the caller assumes the value can be safely sent to other isolation domains}}
296
300
// expected-note @-2 {{'Optional<T>' is a non-Sendable type}}
297
301
}
302
+
303
+
func useBlock<T>(block:()throws->T)throws->sending T {
304
+
fatalError()
305
+
}
306
+
307
+
extensionMyActor{
308
+
// This shouldn't emit any errors. We used to error on returning result.
309
+
publicfunc withContext<T>(_ block: sending ()throws->T)asyncthrows->sending T {
0 commit comments