Skip to content

Commit 8fe9df4

Browse files
committed
Sema: DeclChecker::visitConstructorDecl() does everything in the 'first pass'
1 parent 97227c2 commit 8fe9df4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6295,15 +6295,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
62956295
}
62966296

62976297
void visitConstructorDecl(ConstructorDecl *CD) {
6298-
if (!IsFirstPass) {
6299-
if (CD->getBody()) {
6300-
TC.definedFunctions.push_back(CD);
6301-
} else if (requiresDefinition(CD)) {
6302-
// Complain if we should have a body.
6303-
TC.diagnose(CD->getLoc(), diag::missing_initializer_def);
6304-
}
6305-
}
6306-
63076298
if (!IsFirstPass) {
63086299
return;
63096300
}
@@ -6352,6 +6343,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
63526343

63536344
TC.checkDeclAttributes(CD);
63546345
checkAccessControl(TC, CD);
6346+
6347+
if (CD->hasBody() && !CD->isMemberwiseInitializer()) {
6348+
TC.definedFunctions.push_back(CD);
6349+
} else if (requiresDefinition(CD)) {
6350+
// Complain if we should have a body.
6351+
TC.diagnose(CD->getLoc(), diag::missing_initializer_def);
6352+
}
63556353
}
63566354

63576355
void visitDestructorDecl(DestructorDecl *DD) {
@@ -9035,6 +9033,7 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
90359033
// We have a designated initializer. Create an override of it.
90369034
if (auto ctor = createDesignatedInitOverride(
90379035
*this, classDecl, superclassCtor, kind)) {
9036+
Context.addSynthesizedDecl(ctor);
90389037
classDecl->addMember(ctor);
90399038
}
90409039
}
@@ -9265,6 +9264,9 @@ void TypeChecker::defineDefaultConstructor(NominalTypeDecl *decl) {
92659264
// Create an empty body for the default constructor. The type-check of the
92669265
// constructor body will introduce default initializations of the members.
92679266
ctor->setBody(BraceStmt::create(Context, SourceLoc(), { }, SourceLoc()));
9267+
9268+
// Make sure we type check the constructor later.
9269+
Context.addSynthesizedDecl(ctor);
92689270
}
92699271

92709272
static void validateAttributes(TypeChecker &TC, Decl *D) {

0 commit comments

Comments
 (0)