@@ -1056,9 +1056,6 @@ namespace {
1056
1056
// / Keep track of acceptable DiscardAssignmentExpr's.
1057
1057
llvm::SmallPtrSet<DiscardAssignmentExpr*, 2 > CorrectDiscardAssignmentExprs;
1058
1058
1059
- // / The current number of nested \c SequenceExprs that we're within.
1060
- unsigned SequenceExprDepth = 0 ;
1061
-
1062
1059
// / The current number of nested \c SingleValueStmtExprs that we're within.
1063
1060
unsigned SingleValueStmtExprDepth = 0 ;
1064
1061
@@ -1127,6 +1124,16 @@ namespace {
1127
1124
PreWalkResult<Expr *> walkToExprPre (Expr *expr) override {
1128
1125
auto &diags = Ctx.Diags ;
1129
1126
1127
+ // Fold sequence expressions.
1128
+ if (auto *seqExpr = dyn_cast<SequenceExpr>(expr)) {
1129
+ auto result = TypeChecker::foldSequence (seqExpr, DC);
1130
+ result = result->walk (*this );
1131
+ if (!result)
1132
+ return Action::Stop ();
1133
+ // Already walked.
1134
+ return Action::SkipNode (result);
1135
+ }
1136
+
1130
1137
// FIXME(diagnostics): `InOutType` could appear here as a result
1131
1138
// of successful re-typecheck of the one of the sub-expressions e.g.
1132
1139
// `let _: Int = { (s: inout S) in s.bar() }`. On the first
@@ -1158,11 +1165,9 @@ namespace {
1158
1165
return Action::Stop ();
1159
1166
1160
1167
// If we're going to recurse, record this expression on the stack.
1161
- if (recursive) {
1162
- if (isa<SequenceExpr>(expr))
1163
- SequenceExprDepth++;
1168
+ if (recursive)
1164
1169
ExprStack.push_back (expr);
1165
- }
1170
+
1166
1171
return Action::VisitNodeIf (recursive, expr);
1167
1172
};
1168
1173
@@ -1292,17 +1297,6 @@ namespace {
1292
1297
assert (ExprStack.back () == expr);
1293
1298
ExprStack.pop_back ();
1294
1299
1295
- // Fold sequence expressions.
1296
- if (auto *seqExpr = dyn_cast<SequenceExpr>(expr)) {
1297
- auto result = TypeChecker::foldSequence (seqExpr, DC);
1298
- SequenceExprDepth--;
1299
- result = result->walk (*this );
1300
- if (!result)
1301
- return Action::Stop ();
1302
-
1303
- return Action::Continue (result);
1304
- }
1305
-
1306
1300
// Type check the type parameters in an UnresolvedSpecializeExpr.
1307
1301
if (auto *us = dyn_cast<UnresolvedSpecializeExpr>(expr)) {
1308
1302
if (auto *typeExpr = simplifyUnresolvedSpecializeExpr (us))
@@ -1426,12 +1420,9 @@ namespace {
1426
1420
return Action::Continue (simplified);
1427
1421
1428
1422
// Diagnose a '_' that isn't on the immediate LHS of an assignment. We
1429
- // skip diagnostics if we've explicitly marked the expression as valid,
1430
- // or if we're inside a SequenceExpr (since the whole tree will be
1431
- // re-checked when we finish folding anyway).
1423
+ // skip diagnostics if we've explicitly marked the expression as valid.
1432
1424
if (auto *DAE = dyn_cast<DiscardAssignmentExpr>(expr)) {
1433
- if (!CorrectDiscardAssignmentExprs.count (DAE) &&
1434
- SequenceExprDepth == 0 ) {
1425
+ if (!CorrectDiscardAssignmentExprs.count (DAE)) {
1435
1426
ctx.Diags .diagnose (expr->getLoc (),
1436
1427
diag::discard_expr_outside_of_assignment);
1437
1428
return Action::Stop ();
@@ -1688,7 +1679,7 @@ bool PreCheckExpression::possiblyInTypeContext(Expr *E) {
1688
1679
// / been explicitly marked as correct, and the current AST state allows it.
1689
1680
bool PreCheckExpression::canSimplifyDiscardAssignmentExpr (
1690
1681
DiscardAssignmentExpr *DAE) {
1691
- return !CorrectDiscardAssignmentExprs.count (DAE) && SequenceExprDepth == 0 &&
1682
+ return !CorrectDiscardAssignmentExprs.count (DAE) &&
1692
1683
possiblyInTypeContext (DAE);
1693
1684
}
1694
1685
0 commit comments