[CSClosure] Make sure that body is always updated after solution application

It's possible that solution application either modifies or replaces the
`BraceStmt` that represents closure body, so we need to make sure that
body is always updated.
This commit is contained in:
Pavel Yaskevich
2021-12-08 11:58:28 -08:00
parent eda3824fd0
commit 5700516f2d

View File

@@ -1473,11 +1473,13 @@ bool ConstraintSystem::applySolutionToBody(Solution &solution,
auto closureType = cs.getType(closure)->castTo<FunctionType>();
ClosureConstraintApplication application(
solution, closure, closureType->getResult(), rewriteTarget);
application.visit(closure->getBody());
auto body = application.visit(closure->getBody());
if (application.hadError)
if (!body || application.hadError)
return true;
closure->setBody(cast<BraceStmt>(body.get<Stmt *>()),
closure->hasSingleExpressionBody());
closure->setBodyState(ClosureExpr::BodyState::TypeCheckedWithSignature);
return false;
}