Skip to content

Commit 450bc77

Browse files
authored
Merge pull request #35275 from DougGregor/looser-override-witness-isolation-objc
2 parents a15c3b9 + f157c79 commit 450bc77

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,6 +2016,12 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
20162016
if (isolation == overriddenIsolation)
20172017
return;
20182018

2019+
// If the overridden declaration is from Objective-C with no actor annotation,
2020+
// and the overriding declaration has been placed in a global actor, allow it.
2021+
if (overridden->hasClangNode() && !overriddenIsolation &&
2022+
isolation.getKind() == ActorIsolation::GlobalActor)
2023+
return;
2024+
20192025
// Isolation mismatch. Diagnose it.
20202026
value->diagnose(
20212027
diag::actor_isolation_override_mismatch, isolation,

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2739,7 +2739,11 @@ bool ConformanceChecker::checkActorIsolation(
27392739

27402740
// If the witness has a global actor but the requirement does not, we have
27412741
// an isolation error.
2742-
if (witnessGlobalActor && !requirementGlobalActor) {
2742+
//
2743+
// However, we allow this case when the requirement was imported, because
2744+
// it might not have been annotated.
2745+
if (witnessGlobalActor && !requirementGlobalActor &&
2746+
!requirement->hasClangNode()) {
27432747
witness->diagnose(
27442748
diag::global_actor_isolated_witness, witness->getDescriptiveKind(),
27452749
witness->getName(), witnessGlobalActor, Proto->getName());

test/decl/protocol/conforms/objc_async.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// REQUIRES: objc_interop
44
// REQUIRES: concurrency
55
import Foundation
6+
import ObjectiveC
67
import ObjCConcurrency
78

89
// Conform via async method
@@ -51,3 +52,22 @@ extension C5: ConcurrentProtocol {
5152
completionHandler?("hello")
5253
}
5354
}
55+
56+
// Global actors.
57+
actor class SomeActor { }
58+
59+
@globalActor
60+
struct SomeGlobalActor {
61+
static let shared = SomeActor()
62+
}
63+
64+
class C6: ConcurrentProtocol {
65+
@SomeGlobalActor
66+
func askUser(toSolvePuzzle puzzle: String) async throws -> String { "" }
67+
68+
func askUser(toJumpThroughHoop hoop: String) async -> String { "hello" }
69+
}
70+
71+
class C7: NSObject {
72+
@SomeGlobalActor override var description: String { "on an actor" }
73+
}

0 commit comments

Comments
 (0)