Skip to content

Commit 4bbca6a

Browse files
committed
Calling @_unsafeInheritExecutor functions doesn't exit the current actor.
Fixes a spurious warning reported by rdar://95777456.
1 parent e937510 commit 4bbca6a

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
@@ -5053,7 +5053,9 @@ ActorReferenceResult ActorReferenceResult::forReference(
50535053
if (!declIsolation.isActorIsolated()) {
50545054
// If the declaration is asynchronous and we are in an actor-isolated
50555055
// context (of any kind), then we exit the actor to the nonisolated context.
5056-
if (isAsyncDecl(declRef) && contextIsolation.isActorIsolated())
5056+
if (isAsyncDecl(declRef) && contextIsolation.isActorIsolated() &&
5057+
!declRef.getDecl()->getAttrs()
5058+
.hasAttribute<UnsafeInheritExecutorAttr>())
50575059
return forExitsActorToNonisolated(contextIsolation);
50585060

50595061
// 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)