@@ -1054,9 +1054,6 @@ namespace {
1054
1054
// / Keep track of acceptable DiscardAssignmentExpr's.
1055
1055
llvm::SmallPtrSet<DiscardAssignmentExpr*, 2 > CorrectDiscardAssignmentExprs;
1056
1056
1057
- // / The current number of nested \c SingleValueStmtExprs that we're within.
1058
- unsigned SingleValueStmtExprDepth = 0 ;
1059
-
1060
1057
// / Simplify expressions which are type sugar productions that got parsed
1061
1058
// / as expressions due to the parser not knowing which identifiers are
1062
1059
// / type names.
@@ -1213,13 +1210,6 @@ namespace {
1213
1210
if (auto closure = dyn_cast<ClosureExpr>(expr))
1214
1211
return finish (walkToClosureExprPre (closure), expr);
1215
1212
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
-
1223
1213
if (auto *unresolved = dyn_cast<UnresolvedDeclRefExpr>(expr))
1224
1214
return finish (true , TypeChecker::resolveDeclRefExpr (unresolved, DC));
1225
1215
@@ -1321,10 +1311,6 @@ namespace {
1321
1311
DC = ce->getParent ();
1322
1312
}
1323
1313
1324
- // Restore the depth for the single value stmt counter.
1325
- if (isa<SingleValueStmtExpr>(expr))
1326
- SingleValueStmtExprDepth -= 1 ;
1327
-
1328
1314
if (auto *apply = dyn_cast<ApplyExpr>(expr)) {
1329
1315
// Mark the direct callee as being a callee.
1330
1316
markDirectCallee (apply->getFn ());
@@ -1473,11 +1459,17 @@ namespace {
1473
1459
}
1474
1460
1475
1461
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);
1481
1473
}
1482
1474
};
1483
1475
} // end anonymous namespace
0 commit comments