Add type checks for maps

This commit is contained in:
Jeff 2023-12-20 18:36:42 -05:00
parent d2dcc665bb
commit afa937a697

View File

@ -128,6 +128,10 @@ impl AbstractTree for ValueNode {
let statement =
Statement::from_syntax_node(source, child_syntax_node, context)?;
if let Some(type_definition) = &current_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 <bool> = 'bar' }")
.unwrap_err()
.is_type_check_error(&Error::TypeCheck {
expected: Type::Boolean,
actual: Type::String
}))
}
#[test]
fn evaluate_function() {
let result = evaluate("(fn) <int> { 1 }");