@@ -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
@@ -1237,10 +1242,6 @@ namespace {
1237
1242
auto result = parents.find (expr);
1238
1243
if (result != parents.end ()) {
1239
1244
auto *parent = result->getSecond ();
1240
-
1241
- if (isa<SequenceExpr>(parent))
1242
- return finish (true , expr);
1243
-
1244
1245
SourceLoc lastInnerParenLoc;
1245
1246
// Unwrap to the outermost paren in the sequence.
1246
1247
// e.g. `foo(((&bar))`
@@ -1292,17 +1293,6 @@ namespace {
1292
1293
assert (ExprStack.back () == expr);
1293
1294
ExprStack.pop_back ();
1294
1295
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
1296
// Type check the type parameters in an UnresolvedSpecializeExpr.
1307
1297
if (auto *us = dyn_cast<UnresolvedSpecializeExpr>(expr)) {
1308
1298
if (auto *typeExpr = simplifyUnresolvedSpecializeExpr (us))
@@ -1426,12 +1416,9 @@ namespace {
1426
1416
return Action::Continue (simplified);
1427
1417
1428
1418
// 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).
1419
+ // skip diagnostics if we've explicitly marked the expression as valid.
1432
1420
if (auto *DAE = dyn_cast<DiscardAssignmentExpr>(expr)) {
1433
- if (!CorrectDiscardAssignmentExprs.count (DAE) &&
1434
- SequenceExprDepth == 0 ) {
1421
+ if (!CorrectDiscardAssignmentExprs.count (DAE)) {
1435
1422
ctx.Diags .diagnose (expr->getLoc (),
1436
1423
diag::discard_expr_outside_of_assignment);
1437
1424
return Action::Stop ();
@@ -1688,7 +1675,7 @@ bool PreCheckExpression::possiblyInTypeContext(Expr *E) {
1688
1675
// / been explicitly marked as correct, and the current AST state allows it.
1689
1676
bool PreCheckExpression::canSimplifyDiscardAssignmentExpr (
1690
1677
DiscardAssignmentExpr *DAE) {
1691
- return !CorrectDiscardAssignmentExprs.count (DAE) && SequenceExprDepth == 0 &&
1678
+ return !CorrectDiscardAssignmentExprs.count (DAE) &&
1692
1679
possiblyInTypeContext (DAE);
1693
1680
}
1694
1681
0 commit comments