@@ -7093,9 +7093,8 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
7093
7093
auto type = var->getTypeInContext ();
7094
7094
if (var->hasStorage ()) {
7095
7095
{
7096
- // 'nonisolated' can not be applied to mutable stored properties unless
7097
- // qualified as 'unsafe', or is of a Sendable type on a Sendable
7098
- // value type.
7096
+ // A stored property can be 'nonisolated' if it is a 'Sendable' member
7097
+ // of a 'Sendable' value type.
7099
7098
bool canBeNonisolated = false ;
7100
7099
if (auto nominal = dc->getSelfStructDecl ()) {
7101
7100
if (nominal->getDeclaredTypeInContext ()->isSendableType () &&
@@ -7104,26 +7103,30 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
7104
7103
}
7105
7104
}
7106
7105
7106
+ // Additionally, a stored property of a non-'Sendable' type can be
7107
+ // explicitly marked 'nonisolated'.
7108
+ if (auto parentDecl = dc->getDeclaredTypeInContext ())
7109
+ if (!parentDecl->isSendableType ()) {
7110
+ canBeNonisolated = true ;
7111
+ }
7112
+
7113
+ // Otherwise, this stored property has to be qualified as 'unsafe'.
7107
7114
if (var->supportsMutation () && !attr->isUnsafe () && !canBeNonisolated) {
7108
7115
diagnoseAndRemoveAttr (attr, diag::nonisolated_mutable_storage)
7109
7116
.fixItInsertAfter (attr->getRange ().End , " (unsafe)" );
7110
7117
var->diagnose (diag::nonisolated_mutable_storage_note, var);
7111
7118
return ;
7112
7119
}
7113
- }
7114
7120
7115
- // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable
7116
- // variables.
7117
- if (!attr->isUnsafe () && !type->hasError ()) {
7118
- bool diagnosed = diagnoseIfAnyNonSendableTypes (
7119
- type,
7120
- SendableCheckContext (dc),
7121
- Type (),
7122
- SourceLoc (),
7123
- attr->getLocation (),
7124
- diag::nonisolated_non_sendable);
7125
- if (diagnosed)
7126
- return ;
7121
+ // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable
7122
+ // variables, unless they are a member of a non-'Sendable' type.
7123
+ if (!attr->isUnsafe () && !type->hasError () && !canBeNonisolated) {
7124
+ bool diagnosed = diagnoseIfAnyNonSendableTypes (
7125
+ type, SendableCheckContext (dc), Type (), SourceLoc (),
7126
+ attr->getLocation (), diag::nonisolated_non_sendable);
7127
+ if (diagnosed)
7128
+ return ;
7129
+ }
7127
7130
}
7128
7131
7129
7132
if (auto nominal = dyn_cast<NominalTypeDecl>(dc)) {
0 commit comments