diff --git a/src/compiler.rs b/src/compiler.rs index 300ab68..3e57712 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -588,6 +588,22 @@ impl StmtVisitor for Compiler<'_> { match stmt.op.kind { // normal assignment TokenKind::Eq => { + // Insert the name beforehand, but only if we're compiling a function + // I think this is the only instance where we care about inserting a name before + // it's used + if stmt + .rhs + .as_any_ref() + .downcast_ref::() + .is_some() + { + if self.is_global_scope() { + self.insert_global(name)?; + } else if self.get_local(name).is_none() { + self.insert_local(name.to_string())?; + } + } + // compile RHS self.compile_expr(&stmt.rhs)?;