From 64309a3f86fdeab5a60c560a33e108a289200dbc Mon Sep 17 00:00:00 2001 From: Jamie <2119834+jamieQ@users.noreply.github.com> Date: Tue, 28 Oct 2025 20:30:12 -0500 Subject: [PATCH 1/2] [Sema]: ban the use of 'nonisolated' on actor declarations The combination doesn't make sense, so don't allow it. --- lib/Sema/TypeCheckAttr.cpp | 9 +++++++++ test/decl/class/actor/basic.swift | 2 ++ test/decl/protocol/special/DistributedActor.swift | 2 ++ 3 files changed, 13 insertions(+) diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index b005626ffe527..dbf0ecdfeab69 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -7982,6 +7982,15 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) { } } + // `nonisolated` on an actor declaration is contradictory. + if (auto *classDecl = dyn_cast(D); + classDecl && classDecl->isExplicitActor()) { + diagnoseAndRemoveAttr(attr, diag::invalid_decl_modifier, attr) + .warnUntilFutureSwiftVersion() + .fixItRemove(attr->getRange()); + return; + } + if (auto VD = dyn_cast(D)) { //'nonisolated(unsafe)' is meaningless for computed properties, functions etc. auto var = dyn_cast(VD); diff --git a/test/decl/class/actor/basic.swift b/test/decl/class/actor/basic.swift index 23749ee114d15..55c18414014bb 100644 --- a/test/decl/class/actor/basic.swift +++ b/test/decl/class/actor/basic.swift @@ -53,3 +53,5 @@ extension A2 { init(doesNotDelegate: ()) {} // expected-error {{designated initializer cannot be declared in an extension of 'A2'}} } + +nonisolated actor A3 {} // expected-warning {{'nonisolated' modifier cannot be applied to this declaration; this will be an error in a future Swift language mode}}{{1-13=}} diff --git a/test/decl/protocol/special/DistributedActor.swift b/test/decl/protocol/special/DistributedActor.swift index f49ccc399db9c..4390f69b6cadc 100644 --- a/test/decl/protocol/special/DistributedActor.swift +++ b/test/decl/protocol/special/DistributedActor.swift @@ -65,6 +65,8 @@ distributed actor D5: P1 { // expected-note@-1{{non-distributed instance method 'dist()'}} } +nonisolated distributed actor D6 {} // expected-warning {{'nonisolated' modifier cannot be applied to this declaration; this will be an error in a future Swift language mode}}{{1-13=}} + // ==== Tests ------------------------------------------------------------------ // Make sure the conformances have been added implicitly. From 65a67cdf583a3c0cff617e7e5af92612312299c2 Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Thu, 30 Oct 2025 13:25:55 +0900 Subject: [PATCH 2/2] Make 'nonisolated actor' a hard error We've searched and can't find any usage of this in the wild, so hope we can get away with banning this outright. --- lib/Sema/TypeCheckAttr.cpp | 1 - test/decl/class/actor/basic.swift | 2 +- test/decl/protocol/special/DistributedActor.swift | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index dbf0ecdfeab69..c44ec26fd85d2 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -7986,7 +7986,6 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) { if (auto *classDecl = dyn_cast(D); classDecl && classDecl->isExplicitActor()) { diagnoseAndRemoveAttr(attr, diag::invalid_decl_modifier, attr) - .warnUntilFutureSwiftVersion() .fixItRemove(attr->getRange()); return; } diff --git a/test/decl/class/actor/basic.swift b/test/decl/class/actor/basic.swift index 55c18414014bb..7a4ffcdbb7cf1 100644 --- a/test/decl/class/actor/basic.swift +++ b/test/decl/class/actor/basic.swift @@ -54,4 +54,4 @@ extension A2 { init(doesNotDelegate: ()) {} // expected-error {{designated initializer cannot be declared in an extension of 'A2'}} } -nonisolated actor A3 {} // expected-warning {{'nonisolated' modifier cannot be applied to this declaration; this will be an error in a future Swift language mode}}{{1-13=}} +nonisolated actor A3 {} // expected-error {{'nonisolated' modifier cannot be applied to this declaration}}{{1-13=}} diff --git a/test/decl/protocol/special/DistributedActor.swift b/test/decl/protocol/special/DistributedActor.swift index 4390f69b6cadc..a3efe499a8390 100644 --- a/test/decl/protocol/special/DistributedActor.swift +++ b/test/decl/protocol/special/DistributedActor.swift @@ -65,7 +65,7 @@ distributed actor D5: P1 { // expected-note@-1{{non-distributed instance method 'dist()'}} } -nonisolated distributed actor D6 {} // expected-warning {{'nonisolated' modifier cannot be applied to this declaration; this will be an error in a future Swift language mode}}{{1-13=}} +nonisolated distributed actor D6 {} // expected-error {{'nonisolated' modifier cannot be applied to this declaration}}{{1-13=}} // ==== Tests ------------------------------------------------------------------