Implement new function syntax

This commit is contained in:
Jeff 2023-12-05 17:40:22 -05:00
parent ed4dd6a819
commit 984b66b0aa
2 changed files with 15 additions and 5 deletions

View File

@ -43,7 +43,7 @@ impl AbstractTree for FunctionCall {
if let Type::Function {
parameter_types,
return_type,
return_type: _,
} = function_type
{
let argument_type_pairs = arguments.iter().zip(parameter_types.iter());
@ -51,7 +51,11 @@ impl AbstractTree for FunctionCall {
for (argument, r#type) in argument_type_pairs {
let argument_type = argument.expected_type(context)?;
r#type.check(&argument_type, context, node, source)?;
if let Type::Function { return_type, .. } = argument_type {
r#type.check(&return_type, context, node, source)?;
} else {
r#type.check(&argument_type, context, node, source)?;
}
}
}
@ -84,6 +88,7 @@ impl AbstractTree for FunctionCall {
}
let variables = context.variables()?;
if let Some(value) = variables.get(key) {
value.clone()
} else {

View File

@ -196,13 +196,18 @@ impl Display for Type {
parameter_types,
return_type,
} => {
write!(f, "fn ")?;
write!(f, "(")?;
for parameter_type in parameter_types {
write!(f, "{parameter_type} ")?;
write!(f, "{parameter_type}")?;
if parameter_type != parameter_types.last().unwrap() {
write!(f, " ")?;
}
}
write!(f, "-> {return_type}")
write!(f, ")")?;
write!(f, " -> {return_type}")
}
Type::Integer => write!(f, "int"),
Type::List(item_type) => write!(f, "[{item_type}]"),