Skip to content

Commit c4f26d1

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

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
@@ -792,6 +792,9 @@ FuncDecl *GetDistributedThunkRequest::evaluate(Evaluator &evaluator,
792792
if (!var->isDistributed())
793793
return nullptr;
794794

795+
if (checkDistributedActorProperty(var, /*diagnose=*/false))
796+
return nullptr;
797+
795798
distributedTarget = var->getAccessor(AccessorKind::Get);
796799
} else {
797800
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: 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

@@ -598,23 +599,26 @@ bool swift::checkDistributedActorProperty(VarDecl *var, bool diagnose) {
598599

599600
/// === Check if the declaration is a valid combination of attributes
600601
if (var->isStatic()) {
601-
var->diagnose(diag::distributed_property_cannot_be_static,
602-
var->getName());
602+
if (diagnose)
603+
var->diagnose(diag::distributed_property_cannot_be_static,
604+
var->getName());
603605
// TODO(distributed): fixit, offer removing the static keyword
604606
return true;
605607
}
606608

607609
// it is not a computed property
608610
if (var->isLet() || var->hasStorageOrWrapsStorage()) {
609-
var->diagnose(diag::distributed_property_can_only_be_computed,
610-
var->getDescriptiveKind(), var->getName());
611+
if (diagnose)
612+
var->diagnose(diag::distributed_property_can_only_be_computed,
613+
var->getDescriptiveKind(), var->getName());
611614
return true;
612615
}
613616

614617
// distributed properties cannot have setters
615618
if (var->getWriteImpl() != swift::WriteImplKind::Immutable) {
616-
var->diagnose(diag::distributed_property_can_only_be_computed_get_only,
617-
var->getName());
619+
if (diagnose)
620+
var->diagnose(diag::distributed_property_can_only_be_computed_get_only,
621+
var->getName());
618622
return true;
619623
}
620624

0 commit comments

Comments
 (0)