[Sema]: ban the use of 'nonisolated' on actor declarations (#85185)

Co-authored-by: Konrad `ktoso` Malawski <konrad.malawski@project13.pl>
This commit is contained in:
Jamie
2025-10-30 16:02:33 -05:00
committed by GitHub
parent a6f4e415cb
commit 0d99dbd2b0
3 changed files with 12 additions and 0 deletions

View File

@@ -7989,6 +7989,14 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
}
}
// `nonisolated` on an actor declaration is contradictory.
if (auto *classDecl = dyn_cast<ClassDecl>(D);
classDecl && classDecl->isExplicitActor()) {
diagnoseAndRemoveAttr(attr, diag::invalid_decl_modifier, attr)
.fixItRemove(attr->getRange());
return;
}
if (auto VD = dyn_cast<ValueDecl>(D)) {
//'nonisolated(unsafe)' is meaningless for computed properties, functions etc.
auto var = dyn_cast<VarDecl>(VD);

View File

@@ -53,3 +53,5 @@ extension A2 {
init(doesNotDelegate: ()) {} // expected-error {{designated initializer cannot be declared in an extension of 'A2'}}
}
nonisolated actor A3 {} // expected-error {{'nonisolated' modifier cannot be applied to this declaration}}{{1-13=}}

View File

@@ -65,6 +65,8 @@ distributed actor D5: P1 {
// expected-note@-1{{non-distributed instance method 'dist()'}}
}
nonisolated distributed actor D6 {} // expected-error {{'nonisolated' modifier cannot be applied to this declaration}}{{1-13=}}
// ==== Tests ------------------------------------------------------------------
// Make sure the conformances have been added implicitly.