diff --git a/src/main.rs b/src/main.rs index 7835ce0..a780ece 100644 --- a/src/main.rs +++ b/src/main.rs @@ -161,15 +161,16 @@ pub fn run(src: &'static str) { match result { Ok(result) => println!("{}", result), - Err(LErr { msg, .. }) => println!("Errors!\n{}", msg), + Err(LErr { msg, .. }) => println!("Ludus panicked!\n{}", msg), } } pub fn main() { let src = " -let bar = :foo -fn foo (foo, bar, ...) -> bar -foo (42) +fn foo () -> { + foo +} +foo () () () () "; run(src); // struct_scalpel::print_dissection_info::() diff --git a/src/validator.rs b/src/validator.rs index bf3e6d8..538e3ff 100644 --- a/src/validator.rs +++ b/src/validator.rs @@ -85,7 +85,9 @@ impl<'a> Validator<'a> { } fn define_fn(&mut self, name: String, info: FnInfo) { - self.locals.push((name, self.span, info)); + let i = self.locals.iter().position(|(n, ..)| *n == name).unwrap(); + let new_binding = (name, self.locals[i].1, info); + self.locals[i] = new_binding; } fn resolved(&self, name: &str) -> bool { @@ -415,8 +417,9 @@ impl<'a> Validator<'a> { self.status.tail_position = tailpos; } Fn(name, clauses, ..) => { + let mut is_declared = false; match self.bound(name) { - Some((_, _, FnInfo::Declared)) => (), + Some((_, _, FnInfo::Declared)) => is_declared = true, None => (), _ => { self.err(format!("name `{name}` is already bound")); @@ -424,6 +427,9 @@ impl<'a> Validator<'a> { } // TODO: devise a placeholder binding for recursive functions + if !is_declared { + self.declare_fn(name.to_string()); + } let from = self.status.used_bindings.len(); let mut arities = HashSet::new();