Skip to content

Commit 8b9cbe2

Browse files
committed
[Concurrency] Always infer actor isolation from overridden declaration.
Infer actor isolation from the overridden declaration unless some other isolation attribute was explicitly specified directly on that declaration. This allows type- and extension-level annotations with a global actor to not break overrides.
1 parent c4c27f6 commit 8b9cbe2

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,16 +1807,15 @@ ActorIsolation ActorIsolationRequest::evaluate(
18071807
// If the declaration overrides another declaration, it must have the same
18081808
// actor isolation.
18091809
if (auto overriddenValue = value->getOverriddenDecl()) {
1810-
if (auto isolation = getActorIsolation(overriddenValue)) {
1811-
SubstitutionMap subs;
1812-
if (auto env = value->getInnermostDeclContext()
1813-
->getGenericEnvironmentOfContext()) {
1814-
subs = SubstitutionMap::getOverrideSubstitutions(
1815-
overriddenValue, value, subs);
1816-
}
1817-
1818-
return inferredIsolation(isolation.subst(subs));
1810+
auto isolation = getActorIsolation(overriddenValue);
1811+
SubstitutionMap subs;
1812+
if (auto env = value->getInnermostDeclContext()
1813+
->getGenericEnvironmentOfContext()) {
1814+
subs = SubstitutionMap::getOverrideSubstitutions(
1815+
overriddenValue, value, subs);
18191816
}
1817+
1818+
return inferredIsolation(isolation.subst(subs));
18201819
}
18211820

18221821
// If this is an accessor, use the actor isolation of its storage

test/Concurrency/global_actor_inference.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,21 @@ struct OtherContainer<U> {
177177
}
178178
}
179179

180+
class SuperclassWithGlobalActors {
181+
@GenericGlobalActor<Int> func f() { }
182+
@GenericGlobalActor<Int> func g() { } // expected-note{{overridden declaration is here}}
183+
func h() { }
184+
}
185+
186+
@GenericGlobalActor<String>
187+
class SubclassWithGlobalActors : SuperclassWithGlobalActors {
188+
override func f() { } // okay: inferred to @GenericGlobalActor<Int>
189+
190+
@GenericGlobalActor<String> override func g() { } // expected-error{{global actor 'GenericGlobalActor<String>'-isolated instance method 'g()' has different actor isolation from global actor 'GenericGlobalActor<Int>'-isolated overridden declaration}}
191+
192+
override func h() { } // okay: inferred to unspecified
193+
}
194+
180195
// ----------------------------------------------------------------------
181196
// Global actor inference for unspecified contexts
182197
// ----------------------------------------------------------------------

0 commit comments

Comments
 (0)