diff --git a/src/compile.rs b/src/compile.rs index 890ff8e..b1b5f62 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -842,15 +842,21 @@ impl Compiler { 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();