Skip to content

Commit d8092f4

Browse files
committed
[NFC] Mark PatternBindingInitializer::getImplicitSelfDecl const
Even though it is not physically const because of the lazy initialization, it is logically const and deserves to be marked as such.
1 parent 4787768 commit d8092f4

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

include/swift/AST/Initializer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class PatternBindingInitializer : public Initializer {
104104

105105
/// If this initializes a single @lazy variable, lazily create a self
106106
/// declaration for it to refer to.
107-
ParamDecl *getImplicitSelfDecl();
107+
ParamDecl *getImplicitSelfDecl() const;
108108

109109
static bool classof(const DeclContext *DC) {
110110
if (auto init = dyn_cast<Initializer>(DC))

lib/AST/Decl.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ PatternBindingDecl *PatternBindingDecl::createDeserialized(
15431543
return PBD;
15441544
}
15451545

1546-
ParamDecl *PatternBindingInitializer::getImplicitSelfDecl() {
1546+
ParamDecl *PatternBindingInitializer::getImplicitSelfDecl() const {
15471547
if (SelfParam)
15481548
return SelfParam;
15491549

@@ -1555,12 +1555,14 @@ ParamDecl *PatternBindingInitializer::getImplicitSelfDecl() {
15551555
: ParamSpecifier::InOut);
15561556

15571557
ASTContext &C = DC->getASTContext();
1558-
SelfParam = new (C) ParamDecl(SourceLoc(), SourceLoc(),
1558+
auto *mutableThis = const_cast<PatternBindingInitializer *>(this);
1559+
auto *LazySelfParam = new (C) ParamDecl(SourceLoc(), SourceLoc(),
15591560
Identifier(), singleVar->getLoc(),
1560-
C.Id_self, this);
1561-
SelfParam->setImplicit();
1562-
SelfParam->setSpecifier(specifier);
1563-
SelfParam->setInterfaceType(DC->getSelfInterfaceType());
1561+
C.Id_self, mutableThis);
1562+
LazySelfParam->setImplicit();
1563+
LazySelfParam->setSpecifier(specifier);
1564+
LazySelfParam->setInterfaceType(DC->getSelfInterfaceType());
1565+
mutableThis->SelfParam = LazySelfParam;
15641566
}
15651567
}
15661568

0 commit comments

Comments
 (0)