@@ -7789,6 +7789,24 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
77897789 auto type = var->getTypeInContext ();
77907790 if (var->hasStorage () || var->hasAttachedPropertyWrapper () ||
77917791 var->getAttrs ().hasAttribute <LazyAttr>()) {
7792+
7793+ if (auto nominal = dyn_cast<NominalTypeDecl>(dc)) {
7794+ // 'nonisolated' can not be applied to stored properties inside
7795+ // distributed actors. Attempts of nonisolated access would be
7796+ // cross-actor, which means they might be accessing on a remote actor,
7797+ // in which case the stored property storage does not exist.
7798+ //
7799+ // The synthesized "id" and "actorSystem" are the only exceptions,
7800+ // because the implementation mirrors them.
7801+ if (nominal->isDistributedActor () &&
7802+ !(var->getName () == Ctx.Id_id ||
7803+ var->getName () == Ctx.Id_actorSystem )) {
7804+ diagnoseAndRemoveAttr (attr,
7805+ diag::nonisolated_distributed_actor_storage);
7806+ return ;
7807+ }
7808+ }
7809+
77927810 {
77937811 // A stored property can be 'nonisolated' if it is a 'Sendable' member
77947812 // of a 'Sendable' value type.
@@ -7844,23 +7862,6 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
78447862 }
78457863 }
78467864
7847- if (auto nominal = dyn_cast<NominalTypeDecl>(dc)) {
7848- // 'nonisolated' can not be applied to stored properties inside
7849- // distributed actors. Attempts of nonisolated access would be
7850- // cross-actor, which means they might be accessing on a remote actor,
7851- // in which case the stored property storage does not exist.
7852- //
7853- // The synthesized "id" and "actorSystem" are the only exceptions,
7854- // because the implementation mirrors them.
7855- if (nominal->isDistributedActor () &&
7856- !(var->getName () == Ctx.Id_id ||
7857- var->getName () == Ctx.Id_actorSystem )) {
7858- diagnoseAndRemoveAttr (attr,
7859- diag::nonisolated_distributed_actor_storage);
7860- return ;
7861- }
7862- }
7863-
78647865 // 'nonisolated(unsafe)' is redundant for 'Sendable' immutables.
78657866 if (attr->isUnsafe () &&
78667867 type->isSendableType () &&
0 commit comments