Skip to content

Commit d9fe401

Browse files
xedinktoso
authored andcommitted
[TypeChecker] Distributed: Verify properties before attempting to synthesize a thunk
1 parent aff7e30 commit d9fe401

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,9 @@ FuncDecl *GetDistributedThunkRequest::evaluate(Evaluator &evaluator,
791791
if (!var->isDistributed())
792792
return nullptr;
793793

794+
if (checkDistributedActorProperty(var, /*diagnose=*/false))
795+
return nullptr;
796+
794797
distributedTarget = var->getAccessor(AccessorKind::Get);
795798
} else {
796799
distributedTarget = originator.get<AbstractFunctionDecl *>();
@@ -815,7 +818,8 @@ FuncDecl *GetDistributedThunkRequest::evaluate(Evaluator &evaluator,
815818
// we must avoid synthesis of the thunk because it'd also have errors,
816819
// giving an ugly user experience (errors in implicit code).
817820
if (distributedTarget->getInterfaceType()->hasError() ||
818-
checkDistributedFunction(distributedTarget)) {
821+
(!isa<AccessorDecl>(distributedTarget) &&
822+
checkDistributedFunction(distributedTarget))) {
819823
return nullptr;
820824
}
821825

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/AST/TypeCheckRequests.h"
2727
#include "swift/AST/TypeVisitor.h"
2828
#include "swift/AST/ExistentialLayout.h"
29+
#include "swift/Basic/Defer.h"
2930

3031
using namespace swift;
3132

@@ -576,6 +577,13 @@ bool swift::checkDistributedActorProperty(VarDecl *var, bool diagnose) {
576577
auto &C = var->getASTContext();
577578
auto DC = var->getDeclContext();
578579

580+
DiagnosticTransaction transaction(C.Diags);
581+
582+
SWIFT_DEFER {
583+
if (!diagnose)
584+
transaction.abort();
585+
};
586+
579587
// without the distributed module, we can't check any of these.
580588
if (!ensureDistributedModuleLoaded(var))
581589
return true;

0 commit comments

Comments
 (0)