ran into another type inference problem
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user