Skip to content

Commit 62558b0

Browse files
committed
Treat 'var's with init accessors as mutable in initializers
1 parent 6a8eabf commit 62558b0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/AST/Decl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7404,6 +7404,11 @@ VarDecl::mutability(const DeclContext *UseDC,
74047404
if (!isLet()) {
74057405
if (hasInitAccessor()) {
74067406
if (auto *ctor = dyn_cast_or_null<ConstructorDecl>(UseDC)) {
7407+
// If we're referencing 'self.', it's mutable.
7408+
if (!base ||
7409+
(*base && ctor->getImplicitSelfDecl() == (*base)->getDecl()))
7410+
return StorageMutability::Mutable;
7411+
74077412
return storageIsMutable(supportsMutation());
74087413
}
74097414
}

0 commit comments

Comments
 (0)