From 3096cf5959238939795a4b33bc327ef16f14dea4 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sat, 16 Dec 2023 20:42:19 -0500 Subject: [PATCH] Fix function parsing --- src/abstract_tree/value_node.rs | 6 +++--- src/error.rs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/abstract_tree/value_node.rs b/src/abstract_tree/value_node.rs index 0465e19..ae02655 100644 --- a/src/abstract_tree/value_node.rs +++ b/src/abstract_tree/value_node.rs @@ -33,7 +33,7 @@ impl AbstractTree for ValueNode { let mut parameters = Vec::new(); let mut parameter_types = Vec::new(); - for index in 2..child_count - 1 { + for index in 2..child_count - 2 { let child = child.child(index).unwrap(); if child.kind() == "identifier" { @@ -258,12 +258,12 @@ mod tests { #[test] fn evaluate_function() { - let result = evaluate("(fn) {true}"); + let result = evaluate("(fn) { 1 }"); let value = result.unwrap(); let function = value.as_function().unwrap(); assert_eq!(&Vec::::with_capacity(0), function.parameters()); - assert_eq!(Ok(&Type::Boolean), function.return_type()); + assert_eq!(Ok(&Type::Integer), function.return_type()); let result = evaluate("(fn x ) {true}"); let value = result.unwrap(); diff --git a/src/error.rs b/src/error.rs index 740b4a9..4ddf435 100644 --- a/src/error.rs +++ b/src/error.rs @@ -216,8 +216,16 @@ impl Error { pub fn is_type_check_error(&self, other: &Error) -> bool { match self { - Error::WithContext { error, .. } => error.as_ref() == other, - _ => self == other, + Error::WithContext { error, .. } => { + debug_assert_eq!(error.as_ref(), other); + + error.as_ref() == other + } + _ => { + debug_assert_eq!(self, other); + + self == other + } } } }