Skip to content

[6.2] [SE-0466] Nested types of nonisolated types don't infer main-actor isolation #83088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
21 changes: 18 additions & 3 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6104,13 +6104,28 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
-> std::optional<std::tuple<InferredActorIsolation, ValueDecl *,
std::optional<ActorIsolation>>> {
// Default global actor isolation does not apply to any declarations
// within actors and distributed actors.
bool inActorContext = false;
// within actors and distributed actors, nor does it apply in a
// nonisolated type.
auto *dc = value->getInnermostDeclContext();
while (dc && !inActorContext) {
while (dc) {
if (auto *nominal = dc->getSelfNominalTypeDecl()) {
if (nominal->isAnyActor())
return {};

if (dc != dyn_cast<DeclContext>(value)) {
switch (getActorIsolation(nominal)) {
case ActorIsolation::Unspecified:
case ActorIsolation::ActorInstance:
case ActorIsolation::Nonisolated:
case ActorIsolation::NonisolatedUnsafe:
case ActorIsolation::Erased:
case ActorIsolation::CallerIsolationInheriting:
return {};

case ActorIsolation::GlobalActor:
break;
}
}
}
dc = dc->getParent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ enum CK: CodingKey {
case one

func f() { }

struct Nested {
func g() { }
}
}

nonisolated func testCK(x: CK) {
nonisolated func testCK(x: CK, y: CK.Nested) {
x.f() // okay, because CK and CK.f are not @MainActor.
y.g()
}