mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-18 18:45:23 +00:00
Fix break to contain end label
This commit is contained in:
parent
3bf931fbb0
commit
6760d21399
1 changed files with 8 additions and 9 deletions
|
@ -761,13 +761,14 @@ impl Compiler {
|
|||
self.switch_to_block(after_block);
|
||||
}
|
||||
}
|
||||
Break => {
|
||||
if self.ctx.loop_data.is_some() {
|
||||
self.emit(Instruction::Break);
|
||||
} else {
|
||||
Break => match self.ctx.loop_data {
|
||||
Some((_, end)) => {
|
||||
self.emit(Instruction::Break { target: end });
|
||||
}
|
||||
None => {
|
||||
return Err(self.error_loc(CompileErrorType::InvalidBreak, statement.location));
|
||||
}
|
||||
}
|
||||
},
|
||||
Continue => match self.ctx.loop_data {
|
||||
Some((start, _)) => {
|
||||
self.emit(Instruction::Continue { target: start });
|
||||
|
@ -1373,8 +1374,7 @@ impl Compiler {
|
|||
|
||||
self.compile_jump_if(test, false, else_block)?;
|
||||
|
||||
let was_in_loop = self.ctx.loop_data;
|
||||
self.ctx.loop_data = Some((while_block, after_block));
|
||||
let was_in_loop = self.ctx.loop_data.replace((while_block, after_block));
|
||||
self.compile_statements(body)?;
|
||||
self.ctx.loop_data = was_in_loop;
|
||||
self.emit(Instruction::Jump {
|
||||
|
@ -1487,8 +1487,7 @@ impl Compiler {
|
|||
self.compile_store(target)?;
|
||||
};
|
||||
|
||||
let was_in_loop = self.ctx.loop_data;
|
||||
self.ctx.loop_data = Some((for_block, after_block));
|
||||
let was_in_loop = self.ctx.loop_data.replace((for_block, after_block));
|
||||
self.compile_statements(body)?;
|
||||
self.ctx.loop_data = was_in_loop;
|
||||
self.emit(Instruction::Jump { target: for_block });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue