Skip to content

Commit 5bddd98

Browse files
authored
Merge pull request swiftlang#75122 from hborla/isolation-inference-inherited-conformance
[Concurrency] Don't infer actor isolation from inherited conformances.
2 parents 9b9747d + 86f3fe1 commit 5bddd98

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4877,8 +4877,19 @@ getIsolationFromConformances(NominalTypeDecl *nominal) {
48774877
return std::nullopt;
48784878

48794879
std::optional<ActorIsolation> foundIsolation;
4880-
for (auto proto :
4881-
nominal->getLocalProtocols(ConformanceLookupKind::NonStructural)) {
4880+
for (auto conformance :
4881+
nominal->getLocalConformances(ConformanceLookupKind::NonStructural)) {
4882+
4883+
// Don't include inherited conformances. If a conformance is inherited
4884+
// from a superclass, the isolation of the subclass should be inferred
4885+
// from the superclass, which is done directly in ActorIsolationRequest.
4886+
// If the superclass has opted out of global actor inference, such as
4887+
// by conforming to the protocol in an extension, then the subclass should
4888+
// not infer isolation from the protocol.
4889+
if (conformance->getKind() == ProtocolConformanceKind::Inherited)
4890+
continue;
4891+
4892+
auto *proto = conformance->getProtocol();
48824893
switch (auto protoIsolation = getActorIsolation(proto)) {
48834894
case ActorIsolation::ActorInstance:
48844895
case ActorIsolation::Unspecified:

test/Concurrency/global_actor_inference_swift6.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,13 @@ class C2: MainActorSuperclass, InferenceConflictWithSuperclass {
213213
}
214214

215215

216+
class ConformInExtension {}
217+
extension ConformInExtension: InferMainActor {}
218+
219+
class InheritConformance: ConformInExtension {
220+
func f() {}
221+
}
222+
223+
func testInheritedMainActorConformance() {
224+
InheritConformance().f() // okay; this is not main actor isolated
225+
}

0 commit comments

Comments
 (0)