Skip to content

Commit 47e8967

Browse files
committed
[TBDGen] Class inits can appear in extensions, not just ClassDecls.
1 parent d3f92cb commit 47e8967

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/TBDGen/TBDGen.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
110110

111111
void visitClassDecl(ClassDecl *CD);
112112

113+
void visitConstructorDecl(ConstructorDecl *CD);
114+
113115
void visitExtensionDecl(ExtensionDecl *ED);
114116

115117
void visitProtocolDecl(ProtocolDecl *PD);
@@ -369,10 +371,8 @@ void TBDGenVisitor::visitClassDecl(ClassDecl *CD) {
369371
addSymbol(LinkEntity::forFieldOffset(var, /*isIndirect=*/true));
370372
}
371373

372-
// The non-allocating forms of the constructors and destructors.
373-
if (auto ctor = dyn_cast<ConstructorDecl>(value)) {
374-
addSymbol(SILDeclRef(ctor, SILDeclRef::Kind::Initializer));
375-
} else if (auto dtor = dyn_cast<DestructorDecl>(value)) {
374+
// The non-allocating forms of the destructors.
375+
if (auto dtor = dyn_cast<DestructorDecl>(value)) {
376376
// ObjC classes don't have a symbol for their destructor.
377377
if (!isObjC)
378378
addSymbol(SILDeclRef(dtor, SILDeclRef::Kind::Destroyer));
@@ -382,6 +382,16 @@ void TBDGenVisitor::visitClassDecl(ClassDecl *CD) {
382382
visitNominalTypeDecl(CD);
383383
}
384384

385+
void TBDGenVisitor::visitConstructorDecl(ConstructorDecl *CD) {
386+
if (CD->getParent()->getAsClassOrClassExtensionContext()) {
387+
// Class constructors come in two forms, allocating and non-allocating. The
388+
// default ValueDecl handling gives the allocating one, so we have to
389+
// manually include the non-allocating one.
390+
addSymbol(SILDeclRef(CD, SILDeclRef::Kind::Initializer));
391+
}
392+
visitAbstractFunctionDecl(CD);
393+
}
394+
385395
void TBDGenVisitor::visitExtensionDecl(ExtensionDecl *ED) {
386396
if (!ED->getExtendedType()->isExistentialType()) {
387397
addConformances(ED);

0 commit comments

Comments
 (0)