Skip to content

Commit 73530bf

Browse files
authored
Merge pull request #83088 from DougGregor/se-0466-nested-no-inference-6.2
[6.2] [SE-0466] Nested types of nonisolated types don't infer main-actor isolation
2 parents ed65bb9 + a4a39f2 commit 73530bf

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6104,13 +6104,28 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
61046104
-> std::optional<std::tuple<InferredActorIsolation, ValueDecl *,
61056105
std::optional<ActorIsolation>>> {
61066106
// Default global actor isolation does not apply to any declarations
6107-
// within actors and distributed actors.
6108-
bool inActorContext = false;
6107+
// within actors and distributed actors, nor does it apply in a
6108+
// nonisolated type.
61096109
auto *dc = value->getInnermostDeclContext();
6110-
while (dc && !inActorContext) {
6110+
while (dc) {
61116111
if (auto *nominal = dc->getSelfNominalTypeDecl()) {
61126112
if (nominal->isAnyActor())
61136113
return {};
6114+
6115+
if (dc != dyn_cast<DeclContext>(value)) {
6116+
switch (getActorIsolation(nominal)) {
6117+
case ActorIsolation::Unspecified:
6118+
case ActorIsolation::ActorInstance:
6119+
case ActorIsolation::Nonisolated:
6120+
case ActorIsolation::NonisolatedUnsafe:
6121+
case ActorIsolation::Erased:
6122+
case ActorIsolation::CallerIsolationInheriting:
6123+
return {};
6124+
6125+
case ActorIsolation::GlobalActor:
6126+
break;
6127+
}
6128+
}
61146129
}
61156130
dc = dc->getParent();
61166131
}

test/Concurrency/assume_mainactor_typechecker_errors_sendablecheck.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ enum CK: CodingKey {
99
case one
1010

1111
func f() { }
12+
13+
struct Nested {
14+
func g() { }
15+
}
1216
}
1317

14-
nonisolated func testCK(x: CK) {
18+
nonisolated func testCK(x: CK, y: CK.Nested) {
1519
x.f() // okay, because CK and CK.f are not @MainActor.
20+
y.g()
1621
}

0 commit comments

Comments
 (0)