@@ -1755,25 +1755,40 @@ SolutionApplicationToFunctionResult ConstraintSystem::applySolution(
1755
1755
}
1756
1756
1757
1757
bool ConstraintSystem::applySolutionToBody (Solution &solution,
1758
- ClosureExpr *closure ,
1758
+ AnyFunctionRef fn ,
1759
1759
DeclContext *¤tDC,
1760
1760
RewriteTargetFn rewriteTarget) {
1761
- auto &cs = solution.getConstraintSystem ();
1762
1761
// Enter the context of the function before performing any additional
1763
1762
// 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);
1765
1779
1766
- auto closureType = cs.getType (closure)->castTo <FunctionType>();
1767
- SyntacticElementSolutionApplication application (
1768
- solution, closure, closureType->getResult (), rewriteTarget);
1769
1780
auto body = application.apply ();
1770
1781
1771
1782
if (!body || application.hadError )
1772
1783
return true ;
1773
1784
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
+
1777
1792
return false ;
1778
1793
}
1779
1794
0 commit comments