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 <alekratz@gmail.com>
This commit is contained in:
2024-09-30 17:39:41 -07:00
parent 8d1cd710b0
commit e5756d6f1a

View File

@@ -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::<UserFunction>() {
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::<UserFunction>() {
fun.set_name(Rc::new(name.to_string()));
}
}
Ok(())