Skip to content

Commit

Permalink
loop: fix loop after block no terminator
Browse files Browse the repository at this point in the history
  • Loading branch information
douyixuan committed Aug 6, 2024
1 parent 1cbaeb6 commit 251819b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/compiler/for.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func (c *Compiler) compileForNode(v *parser.ForNode) {
}

func (c *Compiler) compileForThreeType(v *parser.ForNode) {
forParent := c.contextBlock
// TODO: create a new context-block for code running inside the for loop
c.compile([]parser.Node{
v.BeforeLoop,
Expand Down Expand Up @@ -56,6 +57,7 @@ func (c *Compiler) compileForThreeType(v *parser.ForNode) {

// Set context to the new block after the loop
c.contextBlock = afterLoopBlock
afterLoopBlock.NewBr(forParent)

// Pop break and continue
c.contextLoopBreak = c.contextLoopBreak[0 : len(c.contextLoopBreak)-1]
Expand Down

0 comments on commit 251819b

Please sign in to comment.