From e5756d6f1a69c2e9ec73ce014c3bc60a135273d1 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Mon, 30 Sep 2024 17:39:41 -0700 Subject: [PATCH] Don't always assume that an assignment statement will result in a constant If an assignment statement has a list as its RHS, it will not create a constant. We now do a conditional lookup of the last constant index instead. Signed-off-by: Alek Ratzloff --- src/compiler.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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(())