@@ -7127,6 +7127,15 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
71277127 // 'nonisolated' can be applied to global and static/class variables
71287128 // that do not have storage.
71297129 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+ }
71307139
71317140 // nonisolated(unsafe) is unsafe, but only under strict concurrency.
71327141 if (attr->isUnsafe () &&
@@ -7149,12 +7158,14 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
71497158 }
71507159 }
71517160
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+ }
71587169
71597170 // Otherwise, this stored property has to be qualified as 'unsafe'.
71607171 if (var->supportsMutation () && !attr->isUnsafe () && !canBeNonisolated) {
@@ -7166,12 +7177,15 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
71667177
71677178 // 'nonisolated' without '(unsafe)' is not allowed on non-Sendable
71687179 // 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 ;
7180+ if (!attr->isUnsafe () && !type->hasError ()) {
7181+ if (!(canBeNonisolated &&
7182+ ctx.LangOpts .hasFeature (Feature::GlobalActorInferenceCutoff))) {
7183+ bool diagnosed = diagnoseIfAnyNonSendableTypes (
7184+ type, SendableCheckContext (dc), Type (), SourceLoc (),
7185+ attr->getLocation (), diag::nonisolated_non_sendable);
7186+ if (diagnosed)
7187+ return ;
7188+ }
71757189 }
71767190 }
71777191
0 commit comments