@@ -6937,18 +6937,30 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
6937
6937
6938
6938
if (auto var = dyn_cast<VarDecl>(D)) {
6939
6939
// stored properties have limitations as to when they can be nonisolated.
6940
+ auto type = var->getTypeInContext ();
6940
6941
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
+ }
6948
6960
}
6949
6961
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.
6952
6964
if (!attr->isUnsafe () && !type->hasError ()) {
6953
6965
bool diagnosed = diagnoseIfAnyNonSendableTypes (
6954
6966
type,
0 commit comments