@@ -1755,25 +1755,40 @@ SolutionApplicationToFunctionResult ConstraintSystem::applySolution(
17551755}
17561756
17571757bool ConstraintSystem::applySolutionToBody (Solution &solution,
1758- ClosureExpr *closure ,
1758+ AnyFunctionRef fn ,
17591759 DeclContext *¤tDC,
17601760 RewriteTargetFn rewriteTarget) {
1761- auto &cs = solution.getConstraintSystem ();
17621761 // Enter the context of the function before performing any additional
17631762 // transformations.
1764- llvm::SaveAndRestore<DeclContext *> savedDC (currentDC, closure);
1763+ llvm::SaveAndRestore<DeclContext *> savedDC (currentDC, fn.getAsDeclContext ());
1764+
1765+ Type resultTy;
1766+
1767+ if (auto transform = solution.getAppliedBuilderTransform (fn)) {
1768+ resultTy = solution.simplifyType (transform->bodyResultType );
1769+ } else if (auto *closure =
1770+ getAsExpr<ClosureExpr>(fn.getAbstractClosureExpr ())) {
1771+ resultTy =
1772+ solution.getResolvedType (closure)->castTo <FunctionType>()->getResult ();
1773+ } else {
1774+ resultTy = fn.getBodyResultType ();
1775+ }
1776+
1777+ SyntacticElementSolutionApplication application (solution, fn, resultTy,
1778+ rewriteTarget);
17651779
1766- auto closureType = cs.getType (closure)->castTo <FunctionType>();
1767- SyntacticElementSolutionApplication application (
1768- solution, closure, closureType->getResult (), rewriteTarget);
17691780 auto body = application.apply ();
17701781
17711782 if (!body || application.hadError )
17721783 return true ;
17731784
1774- closure->setBody (cast<BraceStmt>(body.get <Stmt *>()),
1775- closure->hasSingleExpressionBody ());
1776- closure->setBodyState (ClosureExpr::BodyState::TypeCheckedWithSignature);
1785+ fn.setTypecheckedBody (castToStmt<BraceStmt>(body),
1786+ fn.hasSingleExpressionBody ());
1787+
1788+ if (auto *closure = getAsExpr<ClosureExpr>(fn.getAbstractClosureExpr ())) {
1789+ closure->setBodyState (ClosureExpr::BodyState::TypeCheckedWithSignature);
1790+ }
1791+
17771792 return false ;
17781793}
17791794
0 commit comments