[Constaint system] Add a predicate for when to check closures in enclosing expr

Introduce a new predicate, shouldTypeCheckInEnclosingExpression(), to
determine when the body of a closure should be checked as part of the
enclosing expression rather than separately, and use it in the various
places where "hasSingleExpressionBody()" was used for that purpose.
This commit is contained in:
Doug Gregor
2020-06-03 22:48:58 -07:00
parent 690d6c446b
commit f55e7643fa
8 changed files with 36 additions and 16 deletions

View File

@@ -1701,6 +1701,13 @@ public:
FunctionBuilderBodyPreCheck
PreCheckFunctionBuilderRequest::evaluate(Evaluator &eval,
AnyFunctionRef fn) const {
// We don't want to do the precheck if it will already have happened in
// the enclosing expression.
bool skipPrecheck = false;
if (auto closure = dyn_cast_or_null<ClosureExpr>(
fn.getAbstractClosureExpr()))
skipPrecheck = shouldTypeCheckInEnclosingExpression(closure);
return PreCheckFunctionBuilderApplication(fn, false).run();
}