Skip to content

Commit 23e8340

Browse files
committed
[Sema] Use SyntacticElementTarget::walk to pre-check
1 parent cd0e521 commit 23e8340

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

lib/Sema/PreCheckExpr.cpp

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,37 +2427,17 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
24272427

24282428
bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target) {
24292429
auto *DC = target.getDeclContext();
2430+
auto &ctx = DC->getASTContext();
24302431

2431-
bool hadErrors = false;
2432-
2433-
if (auto *expr = target.getAsExpr()) {
2434-
hadErrors |= preCheckExpression(expr, DC);
2435-
// Even if the pre-check fails, expression still has to be re-set.
2436-
target.setExpr(expr);
2437-
}
2438-
2439-
if (target.isForEachPreamble()) {
2440-
auto *stmt = target.getAsForEachStmt();
2441-
2442-
auto *sequenceExpr = stmt->getParsedSequence();
2443-
auto *whereExpr = stmt->getWhere();
2444-
2445-
hadErrors |= preCheckExpression(sequenceExpr, DC);
2446-
2447-
if (whereExpr) {
2448-
hadErrors |= preCheckExpression(whereExpr, DC);
2449-
}
2450-
2451-
// Update sequence and where expressions to pre-checked versions.
2452-
if (!hadErrors) {
2453-
stmt->setParsedSequence(sequenceExpr);
2432+
FrontendStatsTracer StatsTracer(ctx.Stats, "precheck-target");
2433+
PreCheckExpression preCheck(DC);
24542434

2455-
if (whereExpr)
2456-
stmt->setWhere(whereExpr);
2457-
}
2458-
}
2435+
auto newTarget = target.walk(preCheck);
2436+
if (!newTarget)
2437+
return true;
24592438

2460-
return hadErrors;
2439+
target = *newTarget;
2440+
return false;
24612441
}
24622442

24632443
/// Pre-check the expression, validating any types that occur in the

0 commit comments

Comments
 (0)