diff --git a/src/compiler.rs b/src/compiler.rs index eeb5caf..303b748 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -707,9 +707,10 @@ impl StmtVisitor for Compiler { // TODO - maybe this would be smarter to set up in the AST. I'm 99% sure that the last // object created, if it were a function object, will be what we're assigning it to, but I // want to be 100% sure instead of 99%. - let obj = self.constants.last().unwrap().as_ref(); - if let Some(fun) = obj.borrow_mut().as_any_mut().downcast_mut::() { - fun.set_name(Rc::new(name.to_string())); + if let Some(obj) = self.constants.last() { + if let Some(fun) = obj.borrow_mut().as_any_mut().downcast_mut::() { + fun.set_name(Rc::new(name.to_string())); + } } Ok(())