@@ -6937,18 +6937,30 @@ 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 Sendable
6945+ // value type.
6946+ bool canBeNonisolated = false ;
6947+ if (auto nominal = dc->getSelfStructDecl ()) {
6948+ if (nominal->getDeclaredTypeInContext ()->isSendableType () &&
6949+ !var->isStatic () && type->isSendableType ()) {
6950+ canBeNonisolated = true ;
6951+ }
6952+ }
6953+
6954+ if (var->supportsMutation () && !attr->isUnsafe () && !canBeNonisolated) {
6955+ diagnoseAndRemoveAttr (attr, diag::nonisolated_mutable_storage)
6956+ .fixItInsertAfter (attr->getRange ().End , " (unsafe)" );
6957+ var->diagnose (diag::nonisolated_mutable_storage_note, var);
6958+ return ;
6959+ }
69486960 }
69496961
6950- // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable variables.
6951- auto type = var-> getTypeInContext ();
6962+ // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable
6963+ // variables.
69526964 if (!attr->isUnsafe () && !type->hasError ()) {
69536965 bool diagnosed = diagnoseIfAnyNonSendableTypes (
69546966 type,
0 commit comments