@@ -296,7 +296,9 @@ static void maybeMarkTransparent(FuncDecl *accessor,
296
296
297
297
static AccessorDecl *
298
298
createMaterializeForSetPrototype (AbstractStorageDecl *storage,
299
- FuncDecl *setter, TypeChecker &TC) {
299
+ FuncDecl *getter,
300
+ FuncDecl *setter,
301
+ TypeChecker &TC) {
300
302
auto &ctx = storage->getASTContext ();
301
303
SourceLoc loc = storage->getLoc ();
302
304
@@ -319,7 +321,7 @@ createMaterializeForSetPrototype(AbstractStorageDecl *storage,
319
321
params.push_back (buildIndexForwardingParamList (storage, bufferElements));
320
322
321
323
// The accessor returns (temporary: Builtin.RawPointer,
322
- // callback: Builtin.RawPointer),
324
+ // callback: Optional< Builtin.RawPointer> ),
323
325
// where the first pointer is the materialized address and the
324
326
// second is the address of an optional callback.
325
327
TupleTypeElt retElts[] = {
@@ -349,10 +351,15 @@ createMaterializeForSetPrototype(AbstractStorageDecl *storage,
349
351
// Open-code the setMutating() calculation since we might run before
350
352
// the setter has been type checked.
351
353
Type contextTy = DC->getDeclaredInterfaceType ();
352
- if (contextTy && !contextTy->hasReferenceSemantics () &&
354
+ if (contextTy && !contextTy->hasReferenceSemantics ()) {
355
+ bool hasMutatingSetter =
353
356
!setter->getAttrs ().hasAttribute <NonMutatingAttr>() &&
354
- storage->isSetterMutating ())
355
- materializeForSet->setSelfAccessKind (SelfAccessKind::Mutating);
357
+ storage->isSetterMutating ();
358
+ bool hasMutatingGetter =
359
+ getter->getAttrs ().hasAttribute <MutatingAttr>();
360
+ if (hasMutatingSetter || hasMutatingGetter)
361
+ materializeForSet->setSelfAccessKind (SelfAccessKind::Mutating);
362
+ }
356
363
357
364
materializeForSet->setStatic (storage->isStatic ());
358
365
@@ -847,7 +854,7 @@ static FuncDecl *addMaterializeForSet(AbstractStorageDecl *storage,
847
854
}
848
855
849
856
auto materializeForSet = createMaterializeForSetPrototype (
850
- storage, storage->getSetter (), TC);
857
+ storage, storage->getGetter (), storage-> getSetter (), TC);
851
858
addMemberToContextIfNeeded (materializeForSet, storage->getDeclContext (),
852
859
storage->getSetter ());
853
860
storage->setMaterializeForSetFunc (materializeForSet);
@@ -1815,7 +1822,9 @@ void swift::maybeAddAccessorsToVariable(VarDecl *var, TypeChecker &TC) {
1815
1822
1816
1823
AccessorDecl *materializeForSet = nullptr ;
1817
1824
if (dc->getAsNominalTypeOrNominalTypeExtensionContext ())
1818
- materializeForSet = createMaterializeForSetPrototype (var, setter, TC);
1825
+ materializeForSet = createMaterializeForSetPrototype (var,
1826
+ getter, setter,
1827
+ TC);
1819
1828
1820
1829
var->makeComputed (SourceLoc (), getter, setter, materializeForSet, SourceLoc ());
1821
1830
0 commit comments