mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-14 16:45:25 +00:00
Don't emit None, ReturnValue if the last statement in a function is a return
This commit is contained in:
parent
e5f6d11a12
commit
b8726f03df
1 changed files with 12 additions and 6 deletions
|
@ -842,15 +842,21 @@ impl<O: OutputStream> Compiler<O> {
|
|||
|
||||
let mut flags = self.enter_function(name, args)?;
|
||||
|
||||
let (new_body, doc_str) = get_doc(body);
|
||||
let (body, doc_str) = get_doc(body);
|
||||
|
||||
self.compile_statements(new_body)?;
|
||||
self.compile_statements(body)?;
|
||||
|
||||
// Emit None at end:
|
||||
self.emit(Instruction::LoadConst {
|
||||
value: bytecode::Constant::None,
|
||||
});
|
||||
self.emit(Instruction::ReturnValue);
|
||||
match body.last().map(|s| &s.node) {
|
||||
Some(ast::StatementType::Return { .. }) => {}
|
||||
_ => {
|
||||
self.emit(Instruction::LoadConst {
|
||||
value: bytecode::Constant::None,
|
||||
});
|
||||
self.emit(Instruction::ReturnValue);
|
||||
}
|
||||
}
|
||||
|
||||
let code = self.pop_code_object();
|
||||
self.leave_scope();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue