@@ -6937,18 +6937,32 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
69376937
69386938 if (auto var = dyn_cast<VarDecl>(D)) {
69396939 // stored properties have limitations as to when they can be nonisolated.
6940+ auto type = var->getTypeInContext ();
69406941 if (var->hasStorage ()) {
6941- // 'nonisolated' can not be applied to mutable stored properties unless
6942- // qualified as 'unsafe'.
6943- if (var->supportsMutation () && !attr->isUnsafe ()) {
6944- diagnoseAndRemoveAttr (attr, diag::nonisolated_mutable_storage)
6945- .fixItInsertAfter (attr->getRange ().End , " (unsafe)" );
6946- var->diagnose (diag::nonisolated_mutable_storage_note, var);
6947- return ;
6942+ {
6943+ // 'nonisolated' can not be applied to mutable stored properties unless
6944+ // qualified as 'unsafe', or is of a Sendable type on a
6945+ // globally-isolated value type.
6946+ bool canBeNonisolated = false ;
6947+ if (dc->isTypeContext ()) {
6948+ if (auto nominal = dc->getSelfStructDecl ()) {
6949+ if (!var->isStatic () && type->isSendableType () &&
6950+ getActorIsolation (nominal).isGlobalActor ()) {
6951+ canBeNonisolated = true ;
6952+ }
6953+ }
6954+ }
6955+
6956+ if (var->supportsMutation () && !attr->isUnsafe () && !canBeNonisolated) {
6957+ diagnoseAndRemoveAttr (attr, diag::nonisolated_mutable_storage)
6958+ .fixItInsertAfter (attr->getRange ().End , " (unsafe)" );
6959+ var->diagnose (diag::nonisolated_mutable_storage_note, var);
6960+ return ;
6961+ }
69486962 }
69496963
6950- // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable variables.
6951- auto type = var-> getTypeInContext ();
6964+ // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable
6965+ // variables.
69526966 if (!attr->isUnsafe () && !type->hasError ()) {
69536967 bool diagnosed = diagnoseIfAnyNonSendableTypes (
69546968 type,
0 commit comments