Skip to content

Commit ba481f3

Browse files
committed
[Typechecker] Supress _modify synthesis if the wrapped property has observers
1 parent 216ae87 commit ba481f3

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
@@ -769,6 +769,11 @@ static Expr *buildStorageReference(AccessorDecl *accessor,
769769
auto var = dyn_cast<VarDecl>(decl);
770770
if (!var)
771771
return None;
772+
bool hasObservers = var->getParsedAccessor(AccessorKind::WillSet) ||
773+
var->getParsedAccessor(AccessorKind::DidSet);
774+
if (accessor->isCoroutine() && hasObservers) {
775+
return None;
776+
}
772777
auto mut = var->getPropertyWrapperMutability();
773778
if (!mut)
774779
return None;
@@ -1668,15 +1673,19 @@ synthesizeCoroutineAccessorBody(AccessorDecl *accessor, ASTContext &ctx) {
16681673
? TargetImpl::Ordinary
16691674
: TargetImpl::Implementation);
16701675

1676+
bool hasObservers = storage->getParsedAccessor(AccessorKind::DidSet) ||
1677+
storage->getParsedAccessor(AccessorKind::WillSet);
1678+
16711679
// If this is a variable with an attached property wrapper, then
16721680
// the accessors need to yield the wrappedValue or projectedValue.
16731681
if (auto var = dyn_cast<VarDecl>(storage)) {
1674-
if (var->hasAttachedPropertyWrapper()) {
1682+
if (var->hasAttachedPropertyWrapper() && !hasObservers) {
16751683
target = TargetImpl::Wrapper;
16761684
}
16771685

16781686
if (var->getOriginalWrappedProperty(
1679-
PropertyWrapperSynthesizedPropertyKind::StorageWrapper)) {
1687+
PropertyWrapperSynthesizedPropertyKind::StorageWrapper) &&
1688+
!hasObservers) {
16801689
target = TargetImpl::WrapperStorage;
16811690
}
16821691
}

0 commit comments

Comments
 (0)