@@ -7139,9 +7139,8 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
7139
7139
auto type = var->getTypeInContext ();
7140
7140
if (var->hasStorage ()) {
7141
7141
{
7142
- // 'nonisolated' can not be applied to mutable stored properties unless
7143
- // qualified as 'unsafe', or is of a Sendable type on a Sendable
7144
- // value type.
7142
+ // A stored property can be 'nonisolated' if it is a 'Sendable' member
7143
+ // of a 'Sendable' value type.
7145
7144
bool canBeNonisolated = false ;
7146
7145
if (auto nominal = dc->getSelfStructDecl ()) {
7147
7146
if (nominal->getDeclaredTypeInContext ()->isSendableType () &&
@@ -7150,26 +7149,30 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
7150
7149
}
7151
7150
}
7152
7151
7152
+ // Additionally, a stored property of a non-'Sendable' type can be
7153
+ // explicitly marked 'nonisolated'.
7154
+ if (auto parentDecl = dc->getDeclaredTypeInContext ())
7155
+ if (!parentDecl->isSendableType ()) {
7156
+ canBeNonisolated = true ;
7157
+ }
7158
+
7159
+ // Otherwise, this stored property has to be qualified as 'unsafe'.
7153
7160
if (var->supportsMutation () && !attr->isUnsafe () && !canBeNonisolated) {
7154
7161
diagnoseAndRemoveAttr (attr, diag::nonisolated_mutable_storage)
7155
7162
.fixItInsertAfter (attr->getRange ().End , " (unsafe)" );
7156
7163
var->diagnose (diag::nonisolated_mutable_storage_note, var);
7157
7164
return ;
7158
7165
}
7159
- }
7160
7166
7161
- // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable
7162
- // variables.
7163
- if (!attr->isUnsafe () && !type->hasError ()) {
7164
- bool diagnosed = diagnoseIfAnyNonSendableTypes (
7165
- type,
7166
- SendableCheckContext (dc),
7167
- Type (),
7168
- SourceLoc (),
7169
- attr->getLocation (),
7170
- diag::nonisolated_non_sendable);
7171
- if (diagnosed)
7172
- return ;
7167
+ // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable
7168
+ // variables, unless they are a member of a non-'Sendable' type.
7169
+ if (!attr->isUnsafe () && !type->hasError () && !canBeNonisolated) {
7170
+ bool diagnosed = diagnoseIfAnyNonSendableTypes (
7171
+ type, SendableCheckContext (dc), Type (), SourceLoc (),
7172
+ attr->getLocation (), diag::nonisolated_non_sendable);
7173
+ if (diagnosed)
7174
+ return ;
7175
+ }
7173
7176
}
7174
7177
7175
7178
if (auto nominal = dyn_cast<NominalTypeDecl>(dc)) {
0 commit comments