@@ -7127,6 +7127,15 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
7127
7127
// 'nonisolated' can be applied to global and static/class variables
7128
7128
// that do not have storage.
7129
7129
auto dc = D->getDeclContext ();
7130
+ auto &ctx = D->getASTContext ();
7131
+
7132
+ if (!ctx.LangOpts .hasFeature (Feature::GlobalActorInferenceCutoff)) {
7133
+ if (isa<ProtocolDecl>(D) || isa<ExtensionDecl>(D) || isa<ClassDecl>(D) ||
7134
+ isa<StructDecl>(D) || isa<EnumDecl>(D)) {
7135
+ diagnoseAndRemoveAttr (attr, diag::invalid_decl_modifier, attr);
7136
+ return ;
7137
+ }
7138
+ }
7130
7139
7131
7140
// nonisolated(unsafe) is unsafe, but only under strict concurrency.
7132
7141
if (attr->isUnsafe () &&
@@ -7149,12 +7158,14 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
7149
7158
}
7150
7159
}
7151
7160
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
- }
7161
+ if (ctx.LangOpts .hasFeature (Feature::GlobalActorInferenceCutoff)) {
7162
+ // Additionally, a stored property of a non-'Sendable' type can be
7163
+ // explicitly marked 'nonisolated'.
7164
+ if (auto parentDecl = dc->getDeclaredTypeInContext ())
7165
+ if (!parentDecl->isSendableType ()) {
7166
+ canBeNonisolated = true ;
7167
+ }
7168
+ }
7158
7169
7159
7170
// Otherwise, this stored property has to be qualified as 'unsafe'.
7160
7171
if (var->supportsMutation () && !attr->isUnsafe () && !canBeNonisolated) {
@@ -7164,14 +7175,16 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
7164
7175
return ;
7165
7176
}
7166
7177
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 ;
7178
+ if (ctx.LangOpts .hasFeature (Feature::GlobalActorInferenceCutoff)) {
7179
+ // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable
7180
+ // variables, unless they are a member of a non-'Sendable' type.
7181
+ if (!attr->isUnsafe () && !type->hasError () && !canBeNonisolated) {
7182
+ bool diagnosed = diagnoseIfAnyNonSendableTypes (
7183
+ type, SendableCheckContext (dc), Type (), SourceLoc (),
7184
+ attr->getLocation (), diag::nonisolated_non_sendable);
7185
+ if (diagnosed)
7186
+ return ;
7187
+ }
7175
7188
}
7176
7189
}
7177
7190
0 commit comments