@@ -476,47 +476,25 @@ static bool hasReturnStmt(Stmt *stmt) {
476
476
return finder.hasReturnStmt ;
477
477
}
478
478
479
- bool TypeChecker::typeCheckFunctionBuilderFuncBody (FuncDecl *FD,
480
- Type builderType) {
479
+ BraceStmt *
480
+ TypeChecker::applyFunctionBuilderBodyTransform (FuncDecl *FD,
481
+ BraceStmt *body,
482
+ Type builderType) {
481
483
// Try to build a single result expression.
482
484
BuilderClosureVisitor visitor (Context, nullptr ,
483
485
/* wantExpr=*/ true , builderType);
484
- Expr *returnExpr = visitor.visit (FD-> getBody () );
486
+ Expr *returnExpr = visitor.visit (body );
485
487
if (!returnExpr)
486
- return true ;
488
+ return nullptr ;
487
489
488
490
// Make sure we have a usable result type for the body.
489
491
Type returnType = AnyFunctionRef (FD).getBodyResultType ();
490
492
if (!returnType || returnType->hasError ())
491
- return true ;
492
-
493
- TypeCheckExprOptions options = {};
494
- if (auto opaque = returnType->getAs <OpaqueTypeArchetypeType>()) {
495
- if (opaque->getDecl ()->isOpaqueReturnTypeOfFunction (FD))
496
- options |= TypeCheckExprFlags::ConvertTypeIsOpaqueReturnType;
497
- }
498
-
499
- // If we are performing code-completion inside the functions body, supress
500
- // diagnostics to workaround typechecking performance problems.
501
- if (Context.SourceMgr .rangeContainsCodeCompletionLoc (
502
- FD->getBody ()->getSourceRange ()))
503
- options |= TypeCheckExprFlags::SuppressDiagnostics;
504
-
505
- // Type-check the single result expression.
506
- Type returnExprType = typeCheckExpression (returnExpr, FD,
507
- TypeLoc::withoutLoc (returnType),
508
- CTP_ReturnStmt, options);
509
- if (!returnExprType)
510
- return true ;
511
- assert (returnExprType->isEqual (returnType));
493
+ return nullptr ;
512
494
513
495
auto returnStmt = new (Context) ReturnStmt (SourceLoc (), returnExpr);
514
- auto origBody = FD->getBody ();
515
- auto fakeBody = BraceStmt::create (Context, origBody->getLBraceLoc (),
516
- { returnStmt },
517
- origBody->getRBraceLoc ());
518
- FD->setBody (fakeBody);
519
- return false ;
496
+ return BraceStmt::create (Context, body->getLBraceLoc (), { returnStmt },
497
+ body->getRBraceLoc ());
520
498
}
521
499
522
500
ConstraintSystem::TypeMatchResult ConstraintSystem::applyFunctionBuilder (
0 commit comments