@@ -344,7 +344,8 @@ TypeChecker::typeCheckExpression(
344
344
// First, pre-check the expression, validating any types that occur in the
345
345
// expression and folding sequence expressions.
346
346
if (ConstraintSystem::preCheckExpression(
347
- expr, dc, /*replaceInvalidRefsWithErrors=*/true)) {
347
+ expr, dc, /*replaceInvalidRefsWithErrors=*/true,
348
+ options.contains(TypeCheckExprFlags::LeaveClosureBodyUnchecked))) {
348
349
target.setExpr(expr);
349
350
return None;
350
351
}
@@ -588,14 +589,17 @@ bool TypeChecker::typeCheckForEachBinding(DeclContext *dc, ForEachStmt *stmt) {
588
589
// Precheck the sequence.
589
590
Expr *sequence = stmt->getSequence();
590
591
if (ConstraintSystem::preCheckExpression(
591
- sequence, dc, /*replaceInvalidRefsWithErrors=*/true))
592
+ sequence, dc, /*replaceInvalidRefsWithErrors=*/true,
593
+ /*leaveClosureBodiesUnchecked=*/false))
592
594
return failed();
593
595
stmt->setSequence(sequence);
594
596
595
597
// Precheck the filtering condition.
596
598
if (Expr *whereExpr = stmt->getWhere()) {
597
599
if (ConstraintSystem::preCheckExpression(
598
- whereExpr, dc, /*replaceInvalidRefsWithErrors=*/true))
600
+ whereExpr, dc,
601
+ /*replaceInvalidRefsWithErrors=*/true,
602
+ /*leaveClosureBodiesUnchecked=*/false))
599
603
return failed();
600
604
601
605
stmt->setWhere(whereExpr);
@@ -2052,26 +2056,19 @@ HasDynamicCallableAttributeRequest::evaluate(Evaluator &evaluator,
2052
2056
});
2053
2057
}
2054
2058
2055
- bool swift::shouldTypeCheckInEnclosingExpression(ClosureExpr *expr) {
2056
- if (expr->hasSingleExpressionBody())
2057
- return true;
2058
-
2059
- auto &ctx = expr->getASTContext();
2060
- return !expr->hasEmptyBody() &&
2061
- ctx.TypeCheckerOpts.EnableMultiStatementClosureInference;
2062
- }
2063
-
2064
- void swift::forEachExprInConstraintSystem(
2059
+ void ConstraintSystem::forEachExpr(
2065
2060
Expr *expr, llvm::function_ref<Expr *(Expr *)> callback) {
2066
2061
struct ChildWalker : ASTWalker {
2062
+ ConstraintSystem &CS;
2067
2063
llvm::function_ref<Expr *(Expr *)> callback;
2068
2064
2069
- ChildWalker(llvm::function_ref<Expr *(Expr *)> callback)
2070
- : callback(callback) {}
2065
+ ChildWalker(ConstraintSystem &CS,
2066
+ llvm::function_ref<Expr *(Expr *)> callback)
2067
+ : CS(CS), callback(callback) {}
2071
2068
2072
2069
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
2073
2070
if (auto closure = dyn_cast<ClosureExpr>(E)) {
2074
- if (!shouldTypeCheckInEnclosingExpression (closure))
2071
+ if (!CS.participatesInInference (closure))
2075
2072
return { false, callback(E) };
2076
2073
}
2077
2074
return { true, callback(E) };
@@ -2084,5 +2081,5 @@ void swift::forEachExprInConstraintSystem(
2084
2081
bool walkToTypeReprPre(TypeRepr *T) override { return false; }
2085
2082
};
2086
2083
2087
- expr->walk(ChildWalker(callback));
2084
+ expr->walk(ChildWalker(*this, callback));
2088
2085
}
0 commit comments