@@ -5599,6 +5599,16 @@ void TypeChecker::synthesizeMemberForLookup(NominalTypeDecl *target,
55995599 }
56005600}
56015601
5602+ // / Synthesizer callback for a function body consisting of "return".
5603+ static std::pair<BraceStmt *, bool >
5604+ synthesizeSingleReturnFunctionBody (AbstractFunctionDecl *afd, void *) {
5605+ ASTContext &ctx = afd->getASTContext ();
5606+ SmallVector<ASTNode, 1 > stmts;
5607+ stmts.push_back (new (ctx) ReturnStmt (afd->getLoc (), nullptr ));
5608+ return { BraceStmt::create (ctx, afd->getLoc (), stmts, afd->getLoc (), true ),
5609+ /* isTypeChecked=*/ true };
5610+ }
5611+
56025612void TypeChecker::defineDefaultConstructor (NominalTypeDecl *decl) {
56035613 FrontendStatsTracer StatsTracer (Context.Stats , " define-default-ctor" , decl);
56045614 PrettyStackTraceDecl stackTrace (" defining default constructor for" ,
@@ -5624,11 +5634,8 @@ void TypeChecker::defineDefaultConstructor(NominalTypeDecl *decl) {
56245634 // Add the constructor.
56255635 decl->addMember (ctor);
56265636
5627- // Create an empty body for the default constructor.
5628- SmallVector<ASTNode, 1 > stmts;
5629- stmts.push_back (new (Context) ReturnStmt (decl->getLoc (), nullptr ));
5630- ctor->setBody (BraceStmt::create (Context, SourceLoc (), stmts, SourceLoc ()),
5631- AbstractFunctionDecl::BodyKind::TypeChecked);
5637+ // Lazily synthesize an empty body for the default constructor.
5638+ ctor->setBodySynthesizer (synthesizeSingleReturnFunctionBody);
56325639}
56335640
56345641static void validateAttributes (TypeChecker &TC, Decl *D) {
0 commit comments