Skip to content

Commit 31f8917

Browse files
committed
[AST] InitAccessors: init accessor properties without setters use special write strategy
Such properties could be mutated only within initializer context so they can employ a special "init accessor" strategy. (cherry picked from commit 1e6c919)
1 parent a497c30 commit 31f8917

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,10 +2413,15 @@ getDirectReadAccessStrategy(const AbstractStorageDecl *storage) {
24132413
static AccessStrategy
24142414
getDirectWriteAccessStrategy(const AbstractStorageDecl *storage) {
24152415
switch (storage->getWriteImpl()) {
2416-
case WriteImplKind::Immutable:
2416+
case WriteImplKind::Immutable: {
2417+
if (storage->hasInitAccessor())
2418+
return AccessStrategy::getAccessor(AccessorKind::Init,
2419+
/*dispatch=*/false);
2420+
24172421
assert(isa<VarDecl>(storage) && cast<VarDecl>(storage)->isLet() &&
24182422
"mutation of a immutable variable that isn't a let");
24192423
return AccessStrategy::getStorage();
2424+
}
24202425
case WriteImplKind::Stored:
24212426
return AccessStrategy::getStorage();
24222427
case WriteImplKind::StoredWithObservers:
@@ -2493,7 +2498,9 @@ getOpaqueReadAccessStrategy(const AbstractStorageDecl *storage, bool dispatch) {
24932498
}
24942499

24952500
static AccessStrategy
2496-
getOpaqueWriteAccessStrategy(const AbstractStorageDecl *storage, bool dispatch){
2501+
getOpaqueWriteAccessStrategy(const AbstractStorageDecl *storage, bool dispatch) {
2502+
if (storage->hasInitAccessor() && !storage->getAccessor(AccessorKind::Set))
2503+
return AccessStrategy::getAccessor(AccessorKind::Init, dispatch);
24972504
return AccessStrategy::getAccessor(AccessorKind::Set, dispatch);
24982505
}
24992506

0 commit comments

Comments
 (0)