Skip to content

Commit ae87dbb

Browse files
committed
[Sema] Simplify pattern pre-check skipping logic
We only need to consider the ExprPattern case here, everything else should be skipped.
1 parent 9a04f3f commit ae87dbb

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

lib/Sema/PreCheckExpr.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,9 +1054,6 @@ namespace {
10541054
/// Keep track of acceptable DiscardAssignmentExpr's.
10551055
llvm::SmallPtrSet<DiscardAssignmentExpr*, 2> CorrectDiscardAssignmentExprs;
10561056

1057-
/// The current number of nested \c SingleValueStmtExprs that we're within.
1058-
unsigned SingleValueStmtExprDepth = 0;
1059-
10601057
/// Simplify expressions which are type sugar productions that got parsed
10611058
/// as expressions due to the parser not knowing which identifiers are
10621059
/// type names.
@@ -1213,13 +1210,6 @@ namespace {
12131210
if (auto closure = dyn_cast<ClosureExpr>(expr))
12141211
return finish(walkToClosureExprPre(closure), expr);
12151212

1216-
if (auto *SVE = dyn_cast<SingleValueStmtExpr>(expr)) {
1217-
// Record the scope of a single value stmt expr, as we want to skip
1218-
// pre-checking of any patterns, similar to closures.
1219-
SingleValueStmtExprDepth += 1;
1220-
return finish(true, expr);
1221-
}
1222-
12231213
if (auto *unresolved = dyn_cast<UnresolvedDeclRefExpr>(expr))
12241214
return finish(true, TypeChecker::resolveDeclRefExpr(unresolved, DC));
12251215

@@ -1321,10 +1311,6 @@ namespace {
13211311
DC = ce->getParent();
13221312
}
13231313

1324-
// Restore the depth for the single value stmt counter.
1325-
if (isa<SingleValueStmtExpr>(expr))
1326-
SingleValueStmtExprDepth -= 1;
1327-
13281314
if (auto *apply = dyn_cast<ApplyExpr>(expr)) {
13291315
// Mark the direct callee as being a callee.
13301316
markDirectCallee(apply->getFn());
@@ -1473,11 +1459,17 @@ namespace {
14731459
}
14741460

14751461
PreWalkResult<Pattern *> walkToPatternPre(Pattern *pattern) override {
1476-
// Constraint generation is responsible for pattern verification and
1477-
// type-checking in the body of the closure and single value stmt expr,
1478-
// so there is no need to walk into patterns.
1479-
return Action::SkipNodeIf(
1480-
isa<ClosureExpr>(DC) || SingleValueStmtExprDepth > 0, pattern);
1462+
// In general we can't walk into patterns due to the fact that we don't
1463+
// currently resolve patterns until constraint generation, and therefore
1464+
// shouldn't walk into any expressions that may turn into patterns.
1465+
// One exception to this is if the parent is an expression. In that case,
1466+
// we are type-checking an expression in an ExprPattern, meaning that
1467+
// the pattern will already be resolved, and that we ought to e.g
1468+
// diagnose any stray '_' expressions nested within it. This then also
1469+
// means we should walk into any child pattern if we walked into the
1470+
// parent pattern.
1471+
return Action::VisitNodeIf(Parent.getAsExpr() || Parent.getAsPattern(),
1472+
pattern);
14811473
}
14821474
};
14831475
} // end anonymous namespace

0 commit comments

Comments
 (0)