mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-14 08:35:21 +00:00
Add missing codes for empty statement body
Fix #3704 Compared to previous version of `compile_program_single`, below two codes are skipped when an empty body is given. ```rust self.emit_constant(ConstantData::None); self.emit(Instruction::ReturnValue); ``` Signed-off-by: snowapril <sinjihng@gmail.com>
This commit is contained in:
parent
be43bfaa80
commit
dc1d6616ca
1 changed files with 15 additions and 17 deletions
|
@ -344,12 +344,7 @@ impl Compiler {
|
||||||
) -> CompileResult<()> {
|
) -> CompileResult<()> {
|
||||||
self.symbol_table_stack.push(symbol_table);
|
self.symbol_table_stack.push(symbol_table);
|
||||||
|
|
||||||
let (last, body) = if let Some(splited) = body.split_last() {
|
if let Some((last, body)) = body.split_last() {
|
||||||
splited
|
|
||||||
} else {
|
|
||||||
return Ok(());
|
|
||||||
};
|
|
||||||
|
|
||||||
for statement in body {
|
for statement in body {
|
||||||
if let ast::StmtKind::Expr { value } = &statement.node {
|
if let ast::StmtKind::Expr { value } = &statement.node {
|
||||||
self.compile_expression(value)?;
|
self.compile_expression(value)?;
|
||||||
|
@ -367,8 +362,11 @@ impl Compiler {
|
||||||
self.compile_statement(last)?;
|
self.compile_statement(last)?;
|
||||||
self.emit_constant(ConstantData::None);
|
self.emit_constant(ConstantData::None);
|
||||||
}
|
}
|
||||||
self.emit(Instruction::ReturnValue);
|
} else {
|
||||||
|
self.emit_constant(ConstantData::None);
|
||||||
|
};
|
||||||
|
|
||||||
|
self.emit(Instruction::ReturnValue);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue