Skip to content

Commit 68ca6a2

Browse files
committed
[TypeChecker] Distributed: Verify properties before attempting to synthesize a thunk
1 parent f5cb0ca commit 68ca6a2

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/Sema/CodeSynthesisDistributedActor.cpp

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

825+
if (checkDistributedActorProperty(var, /*diagnose=*/false))
826+
return nullptr;
827+
825828
distributedTarget = var->getAccessor(AccessorKind::Get);
826829
} else {
827830
distributedTarget = originator.get<AbstractFunctionDecl *>();
@@ -846,7 +849,8 @@ FuncDecl *GetDistributedThunkRequest::evaluate(Evaluator &evaluator,
846849
// we must avoid synthesis of the thunk because it'd also have errors,
847850
// giving an ugly user experience (errors in implicit code).
848851
if (distributedTarget->getInterfaceType()->hasError() ||
849-
checkDistributedFunction(distributedTarget)) {
852+
(!isa<AccessorDecl>(distributedTarget) &&
853+
checkDistributedFunction(distributedTarget))) {
850854
return nullptr;
851855
}
852856

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 10 additions & 6 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

@@ -583,23 +584,26 @@ bool swift::checkDistributedActorProperty(VarDecl *var, bool diagnose) {
583584

584585
/// === Check if the declaration is a valid combination of attributes
585586
if (var->isStatic()) {
586-
var->diagnose(diag::distributed_property_cannot_be_static,
587-
var->getName());
587+
if (diagnose)
588+
var->diagnose(diag::distributed_property_cannot_be_static,
589+
var->getName());
588590
// TODO(distributed): fixit, offer removing the static keyword
589591
return true;
590592
}
591593

592594
// it is not a computed property
593595
if (var->isLet() || var->hasStorageOrWrapsStorage()) {
594-
var->diagnose(diag::distributed_property_can_only_be_computed,
595-
var->getDescriptiveKind(), var->getName());
596+
if (diagnose)
597+
var->diagnose(diag::distributed_property_can_only_be_computed,
598+
var->getDescriptiveKind(), var->getName());
596599
return true;
597600
}
598601

599602
// distributed properties cannot have setters
600603
if (var->getWriteImpl() != swift::WriteImplKind::Immutable) {
601-
var->diagnose(diag::distributed_property_can_only_be_computed_get_only,
602-
var->getName());
604+
if (diagnose)
605+
var->diagnose(diag::distributed_property_can_only_be_computed_get_only,
606+
var->getName());
603607
return true;
604608
}
605609

0 commit comments

Comments
 (0)