Skip to content

Commit fc168a0

Browse files
authored
[Distributed] Don't crash when 'open' distributed actor is declared (#85170)
1 parent df5bf83 commit fc168a0

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

lib/AST/Decl.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5565,10 +5565,18 @@ void ValueDecl::copyFormalAccessFrom(const ValueDecl *source,
55655565
access = AccessLevel::FilePrivate;
55665566

55675567
// Only certain declarations can be 'open'.
5568-
if (access == AccessLevel::Open && !isSyntacticallyOverridable()) {
5569-
assert(!isa<ClassDecl>(this) &&
5570-
"copying 'open' onto a class has complications");
5571-
access = AccessLevel::Public;
5568+
if (access == AccessLevel::Open) {
5569+
auto classDecl = dyn_cast<ClassDecl>(source);
5570+
if (classDecl && classDecl->isDistributedActor()) {
5571+
// don't copy 'public'; an 'open distributed actor' is illegal to begin with
5572+
return;
5573+
}
5574+
5575+
if (!isSyntacticallyOverridable()) {
5576+
assert(!isa<ClassDecl>(this) &&
5577+
"copying 'open' onto a class has complications");
5578+
access = AccessLevel::Public;
5579+
}
55725580
}
55735581

55745582
setAccess(access);

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,13 @@ void TypeChecker::checkDistributedActor(SourceFile *SF, NominalTypeDecl *nominal
709709
if (!swift::ensureDistributedModuleLoaded(nominal))
710710
return;
711711

712+
if (nominal->getFormalAccess() == AccessLevel::Open) {
713+
// we should have outright banned 'open' for all actors, but seems we didn't.
714+
// distributed actor synthesis always previously crashed if someone were to
715+
// declare one as open, so we're banning it now, rather than leave it crashing.
716+
(void) nominal->diagnose(diag::access_control_open_bad_decl);
717+
}
718+
712719
auto &C = nominal->getASTContext();
713720
auto loc = nominal->getLoc();
714721
recordRequiredImportAccessLevelForDecl(C.getDistributedActorDecl(), nominal,

validation-test/compiler_crashers/ValueDecl-copyFormalAccessFrom-d1e149.swift

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
// REQUIRES: OS=macosx
3+
import Distributed
4+
distributed open actor a {
5+
}
6+
7+
open distributed actor DA: Comparable {}

0 commit comments

Comments
 (0)