@@ -7010,18 +7010,32 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
70107010
70117011 if (auto var = dyn_cast<VarDecl>(D)) {
70127012 // stored properties have limitations as to when they can be nonisolated.
7013+ auto type = var->getTypeInContext ();
70137014 if (var->hasStorage ()) {
7014- // 'nonisolated' can not be applied to mutable stored properties unless
7015- // qualified as 'unsafe'.
7016- if (var->supportsMutation () && !attr->isUnsafe ()) {
7017- diagnoseAndRemoveAttr (attr, diag::nonisolated_mutable_storage)
7018- .fixItInsertAfter (attr->getRange ().End , " (unsafe)" );
7019- var->diagnose (diag::nonisolated_mutable_storage_note, var);
7020- return ;
7015+ {
7016+ // 'nonisolated' can not be applied to mutable stored properties unless
7017+ // qualified as 'unsafe', or is of a Sendable type on a
7018+ // globally-isolated value type.
7019+ bool canBeNonisolated = false ;
7020+ if (dc->isTypeContext ()) {
7021+ if (auto nominal = dc->getSelfStructDecl ()) {
7022+ if (!var->isStatic () && type->isSendableType () &&
7023+ getActorIsolation (nominal).isGlobalActor ()) {
7024+ canBeNonisolated = true ;
7025+ }
7026+ }
7027+ }
7028+
7029+ if (var->supportsMutation () && !attr->isUnsafe () && !canBeNonisolated) {
7030+ diagnoseAndRemoveAttr (attr, diag::nonisolated_mutable_storage)
7031+ .fixItInsertAfter (attr->getRange ().End , " (unsafe)" );
7032+ var->diagnose (diag::nonisolated_mutable_storage_note, var);
7033+ return ;
7034+ }
70217035 }
70227036
7023- // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable variables.
7024- auto type = var-> getTypeInContext ();
7037+ // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable
7038+ // variables.
70257039 if (!attr->isUnsafe () && !type->hasError ()) {
70267040 bool diagnosed = diagnoseIfAnyNonSendableTypes (
70277041 type,
0 commit comments