diff --git a/compiler/codegen/func_info.go b/compiler/codegen/func_info.go index 2e8747b..8f1d579 100644 --- a/compiler/codegen/func_info.go +++ b/compiler/codegen/func_info.go @@ -142,10 +142,10 @@ func (self *funcInfo) exitScope(endPC int) { self.breaks = self.breaks[:len(self.breaks)-1] a := self.getJmpArgA() - for i := range pendingBreakJmps { - sBx := self.pc() - pendingBreakJmps[i] + for idx := range pendingBreakJmps { + sBx := self.pc() - pendingBreakJmps[idx] i := (sBx+MAXARG_sBx)<<14 | a<<6 | OP_JMP - self.insts[pendingBreakJmps[i]] = uint32(i) + self.insts[pendingBreakJmps[idx]] = uint32(i) } self.scopeLv-- diff --git a/test/basic.lk b/test/basic.lk index c2e9a9b..b108a7c 100644 --- a/test/basic.lk +++ b/test/basic.lk @@ -27,6 +27,16 @@ if #long >= 0 and '' { func(long, #long) } +while true { + if long != nil { + print('break') + } else { + break + } + os.sleep(100) + long = nil +} + func('' and true and 1 ? 'support ternary exp' : 'unreachable') func(6 ~/ 2, 6 & 2, 6 / 2) func(_VERSION, math.pi)