Skip to content
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()
}