@@ -1246,8 +1246,6 @@ void StmtEmitter::visitRepeatWhileStmt(RepeatWhileStmt *S) {
12461246}
12471247
12481248void StmtEmitter::visitForEachStmt (ForEachStmt *S) {
1249- // Emit the 'iterator' variable that we'll be using for iteration.
1250- LexicalScope OuterForScope (SGF, CleanupLocation (S));
12511249
12521250 if (auto *expansion =
12531251 dyn_cast<PackExpansionExpr>(S->getTypeCheckedSequence ())) {
@@ -1256,8 +1254,6 @@ void StmtEmitter::visitForEachStmt(ForEachStmt *S) {
12561254 ->getCanonicalType ());
12571255
12581256 JumpDest loopDest = createJumpDest (S->getBody ());
1259-
1260- // Set the destinations for 'break' and 'continue'.
12611257 JumpDest endDest = createJumpDest (S->getBody ());
12621258
12631259 SGF.emitDynamicPackLoop (
@@ -1271,6 +1267,7 @@ void StmtEmitter::visitForEachStmt(ForEachStmt *S) {
12711267
12721268 SGF.emitExprInto (expansion->getPatternExpr (), letValueInit.get ());
12731269
1270+ // Set the destinations for 'break' and 'continue'.
12741271 SGF.BreakContinueDestStack .push_back ({S, endDest, loopDest});
12751272 visit (S->getBody ());
12761273 SGF.BreakContinueDestStack .pop_back ();
@@ -1284,6 +1281,8 @@ void StmtEmitter::visitForEachStmt(ForEachStmt *S) {
12841281 return ;
12851282 }
12861283
1284+ // Emit the 'iterator' variable that we'll be using for iteration.
1285+ LexicalScope OuterForScope (SGF, CleanupLocation (S));
12871286 SGF.emitPatternBinding (S->getIteratorVar (),
12881287 /* index=*/ 0 , /* debuginfo*/ true );
12891288
0 commit comments