Skip to content

Commit 035bc16

Browse files
committed
[Typechecker] Supress _modify synthesis if the wrapped property has observers
1 parent f087a68 commit 035bc16

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,11 @@ static Expr *buildStorageReference(AccessorDecl *accessor,
760760
auto var = dyn_cast<VarDecl>(decl);
761761
if (!var)
762762
return None;
763+
bool hasObservers = var->getParsedAccessor(AccessorKind::WillSet) ||
764+
var->getParsedAccessor(AccessorKind::DidSet);
765+
if (accessor->isCoroutine() && hasObservers) {
766+
return None;
767+
}
763768
auto mut = var->getPropertyWrapperMutability();
764769
if (!mut)
765770
return None;
@@ -1584,15 +1589,19 @@ synthesizeCoroutineAccessorBody(AccessorDecl *accessor, ASTContext &ctx) {
15841589
? TargetImpl::Ordinary
15851590
: TargetImpl::Implementation);
15861591

1592+
bool hasObservers = storage->getParsedAccessor(AccessorKind::DidSet) ||
1593+
storage->getParsedAccessor(AccessorKind::WillSet);
1594+
15871595
// If this is a variable with an attached property wrapper, then
15881596
// the accessors need to yield the wrappedValue or projectedValue.
15891597
if (auto var = dyn_cast<VarDecl>(storage)) {
1590-
if (var->hasAttachedPropertyWrapper()) {
1598+
if (var->hasAttachedPropertyWrapper() && !hasObservers) {
15911599
target = TargetImpl::Wrapper;
15921600
}
15931601

15941602
if (var->getOriginalWrappedProperty(
1595-
PropertyWrapperSynthesizedPropertyKind::StorageWrapper)) {
1603+
PropertyWrapperSynthesizedPropertyKind::StorageWrapper) &&
1604+
!hasObservers) {
15961605
target = TargetImpl::WrapperStorage;
15971606
}
15981607
}

0 commit comments

Comments
 (0)