|
35 | 35 | passThroughCtx fql.IForExpressionContext |
36 | 36 | kind loopResultKind |
37 | 37 | distinct bool |
38 | | - bodyCount int |
| 38 | + // bodyEnd is the exclusive end of ordinary body entries compiled before finalization. |
| 39 | + bodyEnd int |
39 | 40 | } |
40 | 41 |
|
41 | 42 | loopOperandContext struct { |
@@ -308,8 +309,8 @@ func (c *LoopCompiler) compileInitialization( |
308 | 309 | func (c *LoopCompiler) resolveLoopResultSpec(ctx fql.IForExpressionContext) loopResultSpec { |
309 | 310 | bodies := ctx.AllForExpressionBody() |
310 | 311 | result := loopResultSpec{ |
311 | | - kind: loopResultEffectOnly, |
312 | | - bodyCount: len(bodies), |
| 312 | + kind: loopResultEffectOnly, |
| 313 | + bodyEnd: len(bodies), |
313 | 314 | } |
314 | 315 |
|
315 | 316 | if re := ctx.ReturnExpression(); re != nil { |
@@ -343,7 +344,7 @@ func (c *LoopCompiler) resolveLoopResultSpec(ctx fql.IForExpressionContext) loop |
343 | 344 | if nested := stmt.ForExpression(); nested != nil { |
344 | 345 | result.passThroughCtx = nested |
345 | 346 | result.kind = loopResultPassThrough |
346 | | - result.bodyCount-- |
| 347 | + result.bodyEnd = len(bodies) - 1 |
347 | 348 | } |
348 | 349 | } |
349 | 350 | } |
@@ -641,10 +642,10 @@ func (c *LoopCompiler) compileLoopBody(ctx fql.IForExpressionContext, resultSpec |
641 | 642 |
|
642 | 643 | body := ctx.AllForExpressionBody() |
643 | 644 |
|
644 | | - for i := 0; i < resultSpec.bodyCount; i++ { |
645 | | - if statement := body[i].ForExpressionStatement(); statement != nil { |
| 645 | + for _, entry := range body[:resultSpec.bodyEnd] { |
| 646 | + if statement := entry.ForExpressionStatement(); statement != nil { |
646 | 647 | c.compileForExpressionStatement(statement) |
647 | | - } else if clause := body[i].ForExpressionClause(); clause != nil { |
| 648 | + } else if clause := entry.ForExpressionClause(); clause != nil { |
648 | 649 | c.compileForExpressionClause(clause) |
649 | 650 | } |
650 | 651 | } |
|
0 commit comments