@@ -743,8 +743,6 @@ static Expr *buildStorageReference(AccessorDecl *accessor,
743
743
bool isMemberLValue = isLValue;
744
744
auto propertyWrapperMutability =
745
745
[&](Decl *decl) -> Optional<std::pair<bool , bool >> {
746
- if (accessor->isCoroutine ())
747
- return None;
748
746
auto var = dyn_cast<VarDecl>(decl);
749
747
if (!var)
750
748
return None;
@@ -1527,7 +1525,7 @@ synthesizeSetterBody(AccessorDecl *setter, ASTContext &ctx) {
1527
1525
return synthesizePropertyWrapperSetterBody (setter, ctx);
1528
1526
}
1529
1527
1530
- // Synthesize a getter for the storage wrapper property of a property
1528
+ // Synthesize a setter for the storage wrapper property of a property
1531
1529
// with an attached wrapper.
1532
1530
if (auto original = var->getOriginalWrappedProperty (
1533
1531
PropertyWrapperSynthesizedPropertyKind::StorageWrapper)) {
@@ -1572,6 +1570,19 @@ synthesizeCoroutineAccessorBody(AccessorDecl *accessor, ASTContext &ctx) {
1572
1570
? TargetImpl::Ordinary
1573
1571
: TargetImpl::Implementation);
1574
1572
1573
+ // If this is a variable with an attached property wrapper, then
1574
+ // the accessors need to yield the wrappedValue or projectedValue.
1575
+ if (auto var = dyn_cast<VarDecl>(storage)) {
1576
+ if (var->hasAttachedPropertyWrapper ()) {
1577
+ target = TargetImpl::Wrapper;
1578
+ }
1579
+
1580
+ if (var->getOriginalWrappedProperty (
1581
+ PropertyWrapperSynthesizedPropertyKind::StorageWrapper)) {
1582
+ target = TargetImpl::WrapperStorage;
1583
+ }
1584
+ }
1585
+
1575
1586
SourceLoc loc = storage->getLoc ();
1576
1587
SmallVector<ASTNode, 1 > body;
1577
1588
@@ -1602,8 +1613,11 @@ synthesizeReadCoroutineBody(AccessorDecl *read, ASTContext &ctx) {
1602
1613
static std::pair<BraceStmt *, bool >
1603
1614
synthesizeModifyCoroutineBody (AccessorDecl *modify, ASTContext &ctx) {
1604
1615
#ifndef NDEBUG
1605
- auto impl = modify->getStorage ()->getReadWriteImpl ();
1606
- assert (impl != ReadWriteImplKind::Modify &&
1616
+ auto storage = modify->getStorage ();
1617
+ auto impl = storage->getReadWriteImpl ();
1618
+ auto hasWrapper = isa<VarDecl>(storage) &&
1619
+ cast<VarDecl>(storage)->hasAttachedPropertyWrapper ();
1620
+ assert ((hasWrapper || impl != ReadWriteImplKind::Modify) &&
1607
1621
impl != ReadWriteImplKind::Immutable);
1608
1622
#endif
1609
1623
return synthesizeCoroutineAccessorBody (modify, ctx);
@@ -2249,9 +2263,15 @@ PropertyWrapperMutabilityRequest::evaluate(Evaluator &,
2249
2263
isProjectedValue = true ;
2250
2264
}
2251
2265
2252
- if (var->getParsedAccessor (AccessorKind::Get))
2266
+ // Make sure we don't ignore .swiftinterface files, because those will
2267
+ // have the accessors printed
2268
+ auto varSourceFile = var->getDeclContext ()->getParentSourceFile ();
2269
+ auto isVarNotInInterfaceFile =
2270
+ varSourceFile && varSourceFile->Kind != SourceFileKind::Interface;
2271
+
2272
+ if (var->getParsedAccessor (AccessorKind::Get) && isVarNotInInterfaceFile)
2253
2273
return None;
2254
- if (var->getParsedAccessor (AccessorKind::Set))
2274
+ if (var->getParsedAccessor (AccessorKind::Set) && isVarNotInInterfaceFile )
2255
2275
return None;
2256
2276
2257
2277
// Figure out which member we're looking through.
@@ -2548,7 +2568,8 @@ static void finishPropertyWrapperImplInfo(VarDecl *var,
2548
2568
}
2549
2569
2550
2570
if (wrapperSetterIsUsable)
2551
- info = StorageImplInfo::getMutableComputed ();
2571
+ info = StorageImplInfo (ReadImplKind::Get, WriteImplKind::Set,
2572
+ ReadWriteImplKind::Modify);
2552
2573
else
2553
2574
info = StorageImplInfo::getImmutableComputed ();
2554
2575
}
0 commit comments