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
Task{ // expected-tns-warning {{passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure}}
467
+
completion() // expected-tns-note {{closure captures 'completion' which is accessible to code in the current task}}
468
468
// expected-warning@-1 {{capture of 'completion' with non-Sendable type '@MainActor () -> Void' in a '@Sendable' closure}}
469
469
// expected-warning@-2 {{capture of 'completion' with non-Sendable type '@MainActor () -> Void' in an isolated closure}}
470
470
// expected-note@-3 2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
471
471
// expected-warning@-4 {{expression is 'async' but is not marked with 'await'; this is an error in the Swift 6 language mode}}
472
472
// expected-note@-5 {{calls to parameter 'completion' from outside of its actor context are implicitly asynchronous}}
473
+
// expected-complete-and-tns-warning @-7 {{passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure}}
474
+
// expected-complete-and-tns-note @-7 {{closure captures 'completion' which is accessible to code in the current task}}
Copy file name to clipboardExpand all lines: test/Concurrency/transfernonsendable.swift
+23-5Lines changed: 23 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1671,13 +1671,12 @@ extension MyActor {
1671
1671
_ =self
1672
1672
_ = sc
1673
1673
1674
-
Task{ // expected-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
1675
-
// expected-note @-1 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to initializer 'init(name:priority:operation:)' risks causing races in between local and caller code}}
1676
-
_ = sc
1674
+
Task{ // expected-warning {{passing closure as a 'sending' parameter risks causing data races between 'self'-isolated code and concurrent execution of the closure}}
Task{ // expected-note {{access can happen concurrently}}
1680
-
_ = sc
1678
+
Task{ // expected-warning {{passing closure as a 'sending' parameter risks causing data races between 'self'-isolated code and concurrent execution of the closure}}
// expected-ni-note @-1 {{sending nonisolated(nonsending) task-isolated 'x' to nonisolated global function 'useValueAsyncConcurrent' risks causing data races between nonisolated and nonisolated(nonsending) task-isolated uses}}
2002
2001
// expected-ni-ns-note @-2 {{sending task-isolated 'x' to @concurrent global function 'useValueAsyncConcurrent' risks causing data races between @concurrent and task-isolated uses}}
2003
2002
}
2003
+
2004
+
func avoidThinkingClosureParameterIsSending(){
2005
+
@MainActor
2006
+
finalclassFoo{
2007
+
letvalue=NonSendableKlass()
2008
+
2009
+
func perform(){
2010
+
Task{[value]in
2011
+
await value.asyncCall() // expected-ni-warning {{sending 'value' risks causing data races}}
2012
+
// expected-ni-note @-1 {{sending main actor-isolated 'value' to nonisolated instance method 'asyncCall()' risks causing data races between nonisolated and main actor-isolated uses}}
2013
+
}
2014
+
2015
+
Task{
2016
+
await value.asyncCall() // expected-ni-warning {{sending 'self.value' risks causing data races}}
2017
+
// expected-ni-note @-1 {{sending main actor-isolated 'self.value' to nonisolated instance method 'asyncCall()' risks causing data races between nonisolated and main actor-isolated uses}}
Copy file name to clipboardExpand all lines: test/Concurrency/transfernonsendable_typed_errors.swift
+4-5Lines changed: 4 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -61,13 +61,12 @@ extension MyActor {
61
61
_ =self
62
62
_ = sc
63
63
64
-
Task{ // expected-error {{sending value of non-Sendable type '() async -> ()' risks causing data races}}
65
-
// expected-note @-1 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to initializer 'init(name:priority:operation:)' risks causing races in between local and caller code}}
66
-
_ = sc
64
+
Task{ // expected-error {{passing closure as a 'sending' parameter risks causing data races between 'self'-isolated code and concurrent execution of the closure}}
Task{ // expected-note {{access can happen concurrently}}
70
-
_ = sc
68
+
Task{ // expected-error {{passing closure as a 'sending' parameter risks causing data races between 'self'-isolated code and concurrent execution of the closure}}
0 commit comments