File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -2468,6 +2468,15 @@ namespace {
2468
2468
// If the closure won't execute concurrently with the context in
2469
2469
// which the declaration occurred, it's okay.
2470
2470
auto decl = capture.getDecl ();
2471
+ auto isolation = getActorIsolation (decl);
2472
+
2473
+ // 'nonisolated' local variables are always okay to capture in
2474
+ // 'Sendable' closures because they can be accessed from anywhere.
2475
+ // Note that only 'nonisolated(unsafe)' can be applied to local
2476
+ // variables.
2477
+ if (isolation.isNonisolated ())
2478
+ continue ;
2479
+
2471
2480
auto *context = localFunc.getAsDeclContext ();
2472
2481
auto fnType = localFunc.getType ()->getAs <AnyFunctionType>();
2473
2482
if (!mayExecuteConcurrentlyWith (context, decl->getDeclContext ()))
Original file line number Diff line number Diff line change @@ -367,4 +367,12 @@ final class UseNonisolatedUnsafe: Sendable {
367
367
nonisolated ( unsafe) var x1 : NonSendable = . init( )
368
368
nonisolated ( unsafe) let x2 : NonSendable = . init( )
369
369
nonisolated ( unsafe) var x3 : Int = 0
370
+
371
+ func captureInTask( ) {
372
+ nonisolated ( unsafe) var x = NonSendable ( )
373
+ Task {
374
+ print ( x)
375
+ x = NonSendable ( )
376
+ }
377
+ }
370
378
}
You can’t perform that action at this time.
0 commit comments