1
0

Clean up and improve tests

This commit is contained in:
Jeff 2023-12-16 20:17:38 -05:00
parent ece75d7b9c
commit 6cb2df55f7
4 changed files with 39 additions and 21 deletions

View File

@ -61,12 +61,6 @@ impl AbstractTree for Assignment {
let statement_type = statement.expected_type(context)?;
if let Some(type_definition) = &type_definition {
context.set(
identifier.inner().clone(),
Value::Empty,
Some(type_definition.inner().clone()),
)?;
match operator {
AssignmentOperator::Equal => {
type_definition
@ -98,6 +92,15 @@ impl AbstractTree for Assignment {
}
}
let variable_key = identifier.inner().clone();
let variable_type = if let Some(definition) = &type_definition {
definition.inner().clone()
} else {
statement_type
};
context.set(variable_key, Value::Empty, Some(variable_type))?;
Ok(Assignment {
identifier,
type_definition,

View File

@ -45,8 +45,6 @@ impl AbstractTree for FunctionCall {
{
let expected_type = parameter_types.get(argument_index).unwrap();
println!("{expected_type} {expression_type}");
expected_type
.check(&expression_type)
.map_err(|error| error.at_node(child, source))?;

View File

@ -260,8 +260,7 @@ mod tests {
",
);
assert_eq!(
Err(Error::TypeCheck {
assert!(result.unwrap_err().is_type_check_error(&Error::TypeCheck {
expected: Type::Function {
parameter_types: vec![],
return_type: Box::new(Type::Boolean),
@ -270,8 +269,6 @@ mod tests {
parameter_types: vec![],
return_type: Box::new(Type::Integer),
},
}),
result
);
}));
}
}

View File

@ -255,4 +255,24 @@ mod tests {
assert_eq!(evaluate("{ x = 1, foo = 'bar' }"), Ok(Value::Map(map)));
}
#[test]
fn evaluate_function() {
let result = evaluate("(fn) <bool> {true}");
let value = result.unwrap();
let function = value.as_function().unwrap();
assert_eq!(&Vec::<Identifier>::with_capacity(0), function.parameters());
assert_eq!(Ok(&Type::Boolean), function.return_type());
let result = evaluate("(fn x <bool>) <bool> {true}");
let value = result.unwrap();
let function = value.as_function().unwrap();
assert_eq!(
&vec![Identifier::new("x".to_string())],
function.parameters()
);
assert_eq!(Ok(&Type::Boolean), function.return_type());
}
}