Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,13 @@ ActorIsolation ActorIsolationRequest::evaluate(
return inferredIsolation(isolation);
}

// If this is a dynamic replacement for another function, use the
// actor isolation of the function it replaces.
if (auto replacedDecl = value->getDynamicallyReplacedDecl()) {
if (auto isolation = getActorIsolation(replacedDecl))
return inferredIsolation(isolation);
}

if (shouldInferAttributeInContext(value->getDeclContext())) {
// If the declaration witnesses a protocol requirement that is isolated,
// use that.
Expand Down
2 changes: 2 additions & 0 deletions test/Concurrency/Inputs/dynamically_replaceable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@MainActor
public dynamic func dynamicOnMainActor() { }
13 changes: 12 additions & 1 deletion test/Concurrency/global_actor_inference.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// RUN: %target-typecheck-verify-swift -disable-availability-checking
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/dynamically_replaceable.swiftmodule -module-name dynamically_replaceable -warn-concurrency %S/Inputs/dynamically_replaceable.swift
// RUN: %target-typecheck-verify-swift -I %t -disable-availability-checking
// REQUIRES: concurrency
import dynamically_replaceable

actor SomeActor { }

Expand Down Expand Up @@ -552,3 +555,11 @@ func useFooInADefer() -> String {

return "hello"
}

// ----------------------------------------------------------------------
// Dynamic replacement
// ----------------------------------------------------------------------
@_dynamicReplacement(for: dynamicOnMainActor)
func replacesDynamicOnMainActor() {
onlyOnMainActor()
}