@@ -6125,28 +6125,40 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
61256125 auto globalActorHelper = [&](Type globalActor)
61266126 -> std::optional<std::tuple<InferredActorIsolation, ValueDecl *,
61276127 std::optional<ActorIsolation>>> {
6128- // Default global actor isolation does not apply to any declarations
6129- // within actors and distributed actors, nor does it apply in a
6130- // nonisolated type.
6128+ // Default main actor only applies to top-level declarations and
6129+ // in contexts that are also main actor isolated. It does not apply
6130+ // in {distributed} actor-isolated contexts nor in nonisolated
6131+ // contexts.
6132+
6133+ if (value->getDeclContext ()->isLocalContext ()) {
6134+ // Local storage is always nonisolated; region isolation computes
6135+ // whether the value is in an actor-isolated region based on
6136+ // the initializer expression.
6137+ auto *var = dyn_cast<VarDecl>(value);
6138+ if (var && var->hasStorage ())
6139+ return {};
6140+
6141+ // Other local declarations must check the isolation of their
6142+ // decl context.
6143+ auto contextIsolation =
6144+ getActorIsolationOfContext (value->getDeclContext ());
6145+ if (!contextIsolation.isMainActor ())
6146+ return {};
6147+ }
6148+
6149+ // Members and nested types must check the isolation of the enclosing
6150+ // nominal type.
61316151 auto *dc = value->getInnermostDeclContext ();
61326152 while (dc) {
61336153 if (auto *nominal = dc->getSelfNominalTypeDecl ()) {
61346154 if (nominal->isAnyActor ())
61356155 return {};
61366156
61376157 if (dc != dyn_cast<DeclContext>(value)) {
6138- switch (getActorIsolation (nominal)) {
6139- case ActorIsolation::Unspecified:
6140- case ActorIsolation::ActorInstance:
6141- case ActorIsolation::Nonisolated:
6142- case ActorIsolation::NonisolatedUnsafe:
6143- case ActorIsolation::Erased:
6144- case ActorIsolation::CallerIsolationInheriting:
6145- return {};
6146-
6147- case ActorIsolation::GlobalActor:
6158+ if (getActorIsolation (nominal).isMainActor ())
61486159 break ;
6149- }
6160+
6161+ return {};
61506162 }
61516163 }
61526164 dc = dc->getParent ();
0 commit comments