@@ -6104,28 +6104,40 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
61046104 auto globalActorHelper = [&](Type globalActor)
61056105 -> std::optional<std::tuple<InferredActorIsolation, ValueDecl *,
61066106 std::optional<ActorIsolation>>> {
6107- // Default global actor isolation does not apply to any declarations
6108- // within actors and distributed actors, nor does it apply in a
6109- // nonisolated type.
6107+ // Default main actor only applies to top-level declarations and
6108+ // in contexts that are also main actor isolated. It does not apply
6109+ // in {distributed} actor-isolated contexts nor in nonisolated
6110+ // contexts.
6111+
6112+ if (value->getDeclContext ()->isLocalContext ()) {
6113+ // Local storage is always nonisolated; region isolation computes
6114+ // whether the value is in an actor-isolated region based on
6115+ // the initializer expression.
6116+ auto *var = dyn_cast<VarDecl>(value);
6117+ if (var && var->hasStorage ())
6118+ return {};
6119+
6120+ // Other local declarations must check the isolation of their
6121+ // decl context.
6122+ auto contextIsolation =
6123+ getActorIsolationOfContext (value->getDeclContext ());
6124+ if (!contextIsolation.isMainActor ())
6125+ return {};
6126+ }
6127+
6128+ // Members and nested types must check the isolation of the enclosing
6129+ // nominal type.
61106130 auto *dc = value->getInnermostDeclContext ();
61116131 while (dc) {
61126132 if (auto *nominal = dc->getSelfNominalTypeDecl ()) {
61136133 if (nominal->isAnyActor ())
61146134 return {};
61156135
61166136 if (dc != dyn_cast<DeclContext>(value)) {
6117- switch (getActorIsolation (nominal)) {
6118- case ActorIsolation::Unspecified:
6119- case ActorIsolation::ActorInstance:
6120- case ActorIsolation::Nonisolated:
6121- case ActorIsolation::NonisolatedUnsafe:
6122- case ActorIsolation::Erased:
6123- case ActorIsolation::CallerIsolationInheriting:
6124- return {};
6125-
6126- case ActorIsolation::GlobalActor:
6137+ if (getActorIsolation (nominal).isMainActor ())
61276138 break ;
6128- }
6139+
6140+ return {};
61296141 }
61306142 }
61316143 dc = dc->getParent ();
0 commit comments