Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Property Wrappers] Make sure captures are computed for synthesized p…
…roperty

wrapper accessors.
  • Loading branch information
hborla committed Sep 29, 2020
1 parent 0842b42 commit 9bd3d0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Expand Up @@ -1418,6 +1418,17 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
(void) VD->getPropertyWrapperBackingProperty();
(void) VD->getImplInfo();

if (VD->hasAttachedPropertyWrapper() && VD->getDeclContext()->isLocalContext()) {
// If this is a local wrapped variable, visit the synthesized
// storage and projection first
auto wrapperInfo = VD->getPropertyWrapperBackingPropertyInfo();
assert(wrapperInfo);

visitBoundVariable(wrapperInfo.backingVar);
if (wrapperInfo.projectionVar)
visitBoundVariable(wrapperInfo.projectionVar);
}

// Add the '@_hasStorage' attribute if this property is stored.
if (VD->hasStorage() && !VD->getAttrs().hasAttribute<HasStorageAttr>())
VD->getAttrs().add(new (getASTContext())
Expand Down
6 changes: 4 additions & 2 deletions lib/Sema/TypeCheckStorage.cpp
Expand Up @@ -1147,8 +1147,9 @@ synthesizeTrivialGetterBody(AccessorDecl *getter, TargetImpl target,
body.push_back(returnStmt);
}

// Don't mark local accessors as type-checked - captures still need to be computed.
return { BraceStmt::create(ctx, loc, body, loc, true),
/*isTypeChecked=*/true };
/*isTypeChecked=*/!getter->getDeclContext()->isLocalContext() };
}

/// Synthesize the body of a getter which just directly accesses the
Expand Down Expand Up @@ -1423,8 +1424,9 @@ synthesizeTrivialSetterBodyWithStorage(AccessorDecl *setter,

createPropertyStoreOrCallSuperclassSetter(setter, valueDRE, storageToUse,
target, setterBody, ctx);
// Don't mark local accessors as type-checked - captures still need to be computed.
return { BraceStmt::create(ctx, loc, setterBody, loc, true),
/*isTypeChecked=*/true };
/*isTypeChecked=*/!setter->getDeclContext()->isLocalContext() };
}

static std::pair<BraceStmt *, bool>
Expand Down

0 comments on commit 9bd3d0b

Please sign in to comment.