Skip to content

Commit 3bc8895

Browse files
authored
Merge pull request RustPython#3705 from Snowapril/fix-3704
Add missing emits for empty statement body in `compile_program_single`
2 parents 2e1ed81 + 689c0b6 commit 3bc8895

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

compiler/src/compile.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -344,31 +344,29 @@ impl Compiler {
344344
) -> CompileResult<()> {
345345
self.symbol_table_stack.push(symbol_table);
346346

347-
let (last, body) = if let Some(splited) = body.split_last() {
348-
splited
349-
} else {
350-
return Ok(());
351-
};
347+
if let Some((last, body)) = body.split_last() {
348+
for statement in body {
349+
if let ast::StmtKind::Expr { value } = &statement.node {
350+
self.compile_expression(value)?;
351+
self.emit(Instruction::PrintExpr);
352+
} else {
353+
self.compile_statement(statement)?;
354+
}
355+
}
352356

353-
for statement in body {
354-
if let ast::StmtKind::Expr { value } = &statement.node {
357+
if let ast::StmtKind::Expr { value } = &last.node {
355358
self.compile_expression(value)?;
359+
self.emit(Instruction::Duplicate);
356360
self.emit(Instruction::PrintExpr);
357361
} else {
358-
self.compile_statement(statement)?;
362+
self.compile_statement(last)?;
363+
self.emit_constant(ConstantData::None);
359364
}
360-
}
361-
362-
if let ast::StmtKind::Expr { value } = &last.node {
363-
self.compile_expression(value)?;
364-
self.emit(Instruction::Duplicate);
365-
self.emit(Instruction::PrintExpr);
366365
} else {
367-
self.compile_statement(last)?;
368366
self.emit_constant(ConstantData::None);
369-
}
370-
self.emit(Instruction::ReturnValue);
367+
};
371368

369+
self.emit(Instruction::ReturnValue);
372370
Ok(())
373371
}
374372

0 commit comments

Comments
 (0)