Skip to content

Commit d981fee

Browse files
authored
Merge pull request #59873 from DougGregor/unsafe-inherit-executor-stays-on-actor-5.7
Calling `@_unsafeInheritExecutor` functions doesn't exit the current actor
2 parents 8cb769a + 25911e9 commit d981fee

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5027,7 +5027,9 @@ ActorReferenceResult ActorReferenceResult::forReference(
50275027
if (!declIsolation.isActorIsolated()) {
50285028
// If the declaration is asynchronous and we are in an actor-isolated
50295029
// context (of any kind), then we exit the actor to the nonisolated context.
5030-
if (isAsyncDecl(declRef) && contextIsolation.isActorIsolated())
5030+
if (isAsyncDecl(declRef) && contextIsolation.isActorIsolated() &&
5031+
!declRef.getDecl()->getAttrs()
5032+
.hasAttribute<UnsafeInheritExecutorAttr>())
50315033
return forExitsActorToNonisolated(contextIsolation);
50325034

50335035
// Otherwise, we stay in the same concurrency domain, whether on an actor

test/Concurrency/unsafe_inherit_executor.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ struct A {
2020
func testAsync() async {}
2121
}
2222

23-
24-
@_nonSendable
25-
class NonSendableObject { // expected-note{{class 'NonSendableObject' does not conform to the 'Sendable' protocol}}
23+
class NonSendableObject {
2624
var property = 0
2725
}
2826

@@ -32,7 +30,6 @@ func useNonSendable(object: NonSendableObject) async {}
3230
actor MyActor {
3331
var object = NonSendableObject()
3432
func foo() async {
35-
// expected-warning@+1{{non-sendable type 'NonSendableObject' exiting actor-isolated context in call to non-isolated global function 'useNonSendable(object:)' cannot cross actor boundary}}
3633
await useNonSendable(object: self.object)
3734
}
3835
}

0 commit comments

Comments
 (0)