Skip to content

Commit 295ec46

Browse files
authored
Merge pull request #59872 from DougGregor/unsafe-inherit-executor-stays-on-actor
2 parents 6170437 + 4bbca6a commit 295ec46

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5078,7 +5078,9 @@ ActorReferenceResult ActorReferenceResult::forReference(
50785078
if (!declIsolation.isActorIsolated()) {
50795079
// If the declaration is asynchronous and we are in an actor-isolated
50805080
// context (of any kind), then we exit the actor to the nonisolated context.
5081-
if (isAsyncDecl(declRef) && contextIsolation.isActorIsolated())
5081+
if (isAsyncDecl(declRef) && contextIsolation.isActorIsolated() &&
5082+
!declRef.getDecl()->getAttrs()
5083+
.hasAttribute<UnsafeInheritExecutorAttr>())
50825084
return forExitsActorToNonisolated(contextIsolation);
50835085

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

test/Concurrency/unsafe_inherit_executor.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct A {
2121
}
2222

2323

24-
class NonSendableObject { // expected-note{{class 'NonSendableObject' does not conform to the 'Sendable' protocol}}
24+
class NonSendableObject {
2525
var property = 0
2626
}
2727

@@ -31,7 +31,6 @@ func useNonSendable(object: NonSendableObject) async {}
3131
actor MyActor {
3232
var object = NonSendableObject()
3333
func foo() async {
34-
// expected-warning@+1{{non-sendable type 'NonSendableObject' exiting actor-isolated context in call to non-isolated global function 'useNonSendable(object:)' cannot cross actor boundary}}
3534
await useNonSendable(object: self.object)
3635
}
3736
}

0 commit comments

Comments
 (0)