Skip to content

Commit 0d99dbd

Browse files
jamieQktoso
andauthored
[Sema]: ban the use of 'nonisolated' on actor declarations (#85185)
Co-authored-by: Konrad `ktoso` Malawski <konrad.malawski@project13.pl>
1 parent a6f4e41 commit 0d99dbd

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7989,6 +7989,14 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
79897989
}
79907990
}
79917991

7992+
// `nonisolated` on an actor declaration is contradictory.
7993+
if (auto *classDecl = dyn_cast<ClassDecl>(D);
7994+
classDecl && classDecl->isExplicitActor()) {
7995+
diagnoseAndRemoveAttr(attr, diag::invalid_decl_modifier, attr)
7996+
.fixItRemove(attr->getRange());
7997+
return;
7998+
}
7999+
79928000
if (auto VD = dyn_cast<ValueDecl>(D)) {
79938001
//'nonisolated(unsafe)' is meaningless for computed properties, functions etc.
79948002
auto var = dyn_cast<VarDecl>(VD);

test/decl/class/actor/basic.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ extension A2 {
5353

5454
init(doesNotDelegate: ()) {} // expected-error {{designated initializer cannot be declared in an extension of 'A2'}}
5555
}
56+
57+
nonisolated actor A3 {} // expected-error {{'nonisolated' modifier cannot be applied to this declaration}}{{1-13=}}

test/decl/protocol/special/DistributedActor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ distributed actor D5: P1 {
6565
// expected-note@-1{{non-distributed instance method 'dist()'}}
6666
}
6767

68+
nonisolated distributed actor D6 {} // expected-error {{'nonisolated' modifier cannot be applied to this declaration}}{{1-13=}}
69+
6870
// ==== Tests ------------------------------------------------------------------
6971

7072
// Make sure the conformances have been added implicitly.

0 commit comments

Comments
 (0)