@@ -1056,9 +1056,6 @@ namespace {
10561056 // / Keep track of acceptable DiscardAssignmentExpr's.
10571057 llvm::SmallPtrSet<DiscardAssignmentExpr*, 2 > CorrectDiscardAssignmentExprs;
10581058
1059- // / The current number of nested \c SequenceExprs that we're within.
1060- unsigned SequenceExprDepth = 0 ;
1061-
10621059 // / The current number of nested \c SingleValueStmtExprs that we're within.
10631060 unsigned SingleValueStmtExprDepth = 0 ;
10641061
@@ -1127,6 +1124,16 @@ namespace {
11271124 PreWalkResult<Expr *> walkToExprPre (Expr *expr) override {
11281125 auto &diags = Ctx.Diags ;
11291126
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+
11301137 // FIXME(diagnostics): `InOutType` could appear here as a result
11311138 // of successful re-typecheck of the one of the sub-expressions e.g.
11321139 // `let _: Int = { (s: inout S) in s.bar() }`. On the first
@@ -1158,11 +1165,9 @@ namespace {
11581165 return Action::Stop ();
11591166
11601167 // 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)
11641169 ExprStack.push_back (expr);
1165- }
1170+
11661171 return Action::VisitNodeIf (recursive, expr);
11671172 };
11681173
@@ -1292,17 +1297,6 @@ namespace {
12921297 assert (ExprStack.back () == expr);
12931298 ExprStack.pop_back ();
12941299
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-
13061300 // Type check the type parameters in an UnresolvedSpecializeExpr.
13071301 if (auto *us = dyn_cast<UnresolvedSpecializeExpr>(expr)) {
13081302 if (auto *typeExpr = simplifyUnresolvedSpecializeExpr (us))
@@ -1426,12 +1420,9 @@ namespace {
14261420 return Action::Continue (simplified);
14271421
14281422 // 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.
14321424 if (auto *DAE = dyn_cast<DiscardAssignmentExpr>(expr)) {
1433- if (!CorrectDiscardAssignmentExprs.count (DAE) &&
1434- SequenceExprDepth == 0 ) {
1425+ if (!CorrectDiscardAssignmentExprs.count (DAE)) {
14351426 ctx.Diags .diagnose (expr->getLoc (),
14361427 diag::discard_expr_outside_of_assignment);
14371428 return Action::Stop ();
@@ -1688,7 +1679,7 @@ bool PreCheckExpression::possiblyInTypeContext(Expr *E) {
16881679// / been explicitly marked as correct, and the current AST state allows it.
16891680bool PreCheckExpression::canSimplifyDiscardAssignmentExpr (
16901681 DiscardAssignmentExpr *DAE) {
1691- return !CorrectDiscardAssignmentExprs.count (DAE) && SequenceExprDepth == 0 &&
1682+ return !CorrectDiscardAssignmentExprs.count (DAE) &&
16921683 possiblyInTypeContext (DAE);
16931684}
16941685
0 commit comments