Skip to content

Commit 9bd3d0b

Browse files
committed
[Property Wrappers] Make sure captures are computed for synthesized property
wrapper accessors.
1 parent 0842b42 commit 9bd3d0b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,17 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
14181418
(void) VD->getPropertyWrapperBackingProperty();
14191419
(void) VD->getImplInfo();
14201420

1421+
if (VD->hasAttachedPropertyWrapper() && VD->getDeclContext()->isLocalContext()) {
1422+
// If this is a local wrapped variable, visit the synthesized
1423+
// storage and projection first
1424+
auto wrapperInfo = VD->getPropertyWrapperBackingPropertyInfo();
1425+
assert(wrapperInfo);
1426+
1427+
visitBoundVariable(wrapperInfo.backingVar);
1428+
if (wrapperInfo.projectionVar)
1429+
visitBoundVariable(wrapperInfo.projectionVar);
1430+
}
1431+
14211432
// Add the '@_hasStorage' attribute if this property is stored.
14221433
if (VD->hasStorage() && !VD->getAttrs().hasAttribute<HasStorageAttr>())
14231434
VD->getAttrs().add(new (getASTContext())

lib/Sema/TypeCheckStorage.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,9 @@ synthesizeTrivialGetterBody(AccessorDecl *getter, TargetImpl target,
11471147
body.push_back(returnStmt);
11481148
}
11491149

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

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

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

14301432
static std::pair<BraceStmt *, bool>

0 commit comments

Comments
 (0)