ran into another type inference problem

This commit is contained in:
2024-02-05 17:30:16 -06:00
parent 7def938781
commit 9d41cf0da7
17 changed files with 267 additions and 24 deletions

View File

@@ -118,6 +118,33 @@ impl Expression {
Ok(Value::calculate(op, arg_values)?)
}
Expression::Call(loc, fun, args) => {
let function = fun.eval(stdout, env)?;
match function {
Value::Closure(name, mut closure_env, arguments, body) => {
if args.len() != arguments.len() {
return Err(EvalError::WrongArgCount(
loc.clone(),
name,
arguments.len(),
args.len(),
));
}
closure_env.new_scope();
for (name, value) in arguments.into_iter().zip(args.iter()) {
let value = value.eval(stdout, env)?;
closure_env.insert(name, value);
}
let result = body.eval(stdout, &mut closure_env)?;
closure_env.release_scope();
Ok(result)
}
_ => Err(EvalError::NotAFunction(loc.clone(), function)),
}
}
Expression::Block(_, stmts) => {
let mut result = Value::Void;