@@ -7010,18 +7010,32 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
7010
7010
7011
7011
if (auto var = dyn_cast<VarDecl>(D)) {
7012
7012
// stored properties have limitations as to when they can be nonisolated.
7013
+ auto type = var->getTypeInContext ();
7013
7014
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
+ }
7021
7035
}
7022
7036
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.
7025
7039
if (!attr->isUnsafe () && !type->hasError ()) {
7026
7040
bool diagnosed = diagnoseIfAnyNonSendableTypes (
7027
7041
type,
0 commit comments