Implement new function syntax
This commit is contained in:
parent
ed4dd6a819
commit
984b66b0aa
@ -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,9 +51,13 @@ impl AbstractTree for FunctionCall {
|
||||
for (argument, r#type) in argument_type_pairs {
|
||||
let argument_type = argument.expected_type(context)?;
|
||||
|
||||
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)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let function_call = FunctionCall {
|
||||
function_expression,
|
||||
@ -84,6 +88,7 @@ impl AbstractTree for FunctionCall {
|
||||
}
|
||||
|
||||
let variables = context.variables()?;
|
||||
|
||||
if let Some(value) = variables.get(key) {
|
||||
value.clone()
|
||||
} else {
|
||||
|
@ -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}]"),
|
||||
|
Loading…
Reference in New Issue
Block a user