mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-19 11:05:45 +00:00
Do not pollute stack when if-expression condition evaluated to False
This commit is contained in:
parent
6f063a402d
commit
313ffe6d6a
1 changed files with 5 additions and 1 deletions
|
@ -1426,11 +1426,15 @@ impl Compiler {
|
|||
ast::Expression::IfExpression { test, body, orelse } => {
|
||||
let no_label = self.new_label();
|
||||
let end_label = self.new_label();
|
||||
self.compile_test(test, None, Some(no_label), EvalContext::Expression)?;
|
||||
self.compile_test(test, None, None, EvalContext::Expression)?;
|
||||
self.emit(Instruction::JumpIfFalse { target: no_label });
|
||||
// True case
|
||||
self.compile_expression(body)?;
|
||||
self.emit(Instruction::Jump { target: end_label });
|
||||
// False case
|
||||
self.set_label(no_label);
|
||||
self.compile_expression(orelse)?;
|
||||
// End
|
||||
self.set_label(end_label);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue