mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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);
|
||||
|
||||
@@ -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=}}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user