@@ -7789,6 +7789,24 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
7789
7789
auto type = var->getTypeInContext ();
7790
7790
if (var->hasStorage () || var->hasAttachedPropertyWrapper () ||
7791
7791
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
+
7792
7810
{
7793
7811
// A stored property can be 'nonisolated' if it is a 'Sendable' member
7794
7812
// of a 'Sendable' value type.
@@ -7844,23 +7862,6 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
7844
7862
}
7845
7863
}
7846
7864
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
-
7864
7865
// 'nonisolated(unsafe)' is redundant for 'Sendable' immutables.
7865
7866
if (attr->isUnsafe () &&
7866
7867
type->isSendableType () &&
0 commit comments