From afa937a697ab5ef85f7558d6b6d2b8d3e56da619 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 20 Dec 2023 18:36:42 -0500 Subject: [PATCH] Add type checks for maps --- src/abstract_tree/value_node.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/abstract_tree/value_node.rs b/src/abstract_tree/value_node.rs index f603e4d..fa4bbd1 100644 --- a/src/abstract_tree/value_node.rs +++ b/src/abstract_tree/value_node.rs @@ -128,6 +128,10 @@ impl AbstractTree for ValueNode { let statement = Statement::from_syntax_node(source, child_syntax_node, context)?; + if let Some(type_definition) = ¤t_type { + type_definition.check(&statement.expected_type(context)?)?; + } + child_nodes.insert(current_key.clone(), (statement, current_type.clone())); } } @@ -300,6 +304,16 @@ mod tests { ); } + #[test] + fn evaluate_map_type_errors() { + assert!(evaluate("{ foo = 'bar' }") + .unwrap_err() + .is_type_check_error(&Error::TypeCheck { + expected: Type::Boolean, + actual: Type::String + })) + } + #[test] fn evaluate_function() { let result = evaluate("(fn) { 1 }");