Skip to content

Commit 665360a

Browse files
committed
Fix some bugs involving nameless reporting of errors
1 parent 191f67c commit 665360a

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/ast_walk_interpreter.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl AstWalkInterpreter {
448448
}
449449

450450
let call_sign = func.get_call_sign();
451-
check_args_compat(&arg_vals, &call_sign, fn_call_expr)?;
451+
check_args_compat(&arg_vals, &call_sign, expr, fn_call_expr)?;
452452

453453
let call_func_result = call_func(&func, &arg_vals);
454454
match call_func_result {
@@ -505,13 +505,14 @@ pub fn call_func(func: &Function, arg_vals: &[Value]) -> Result<Option<Value>, R
505505

506506
fn check_args_compat(arg_vals: &[Value],
507507
call_sign: &CallSign,
508-
expr: &ExprNode)
508+
expr: &ExprNode,
509+
full_expr: &ExprNode)
509510
-> Result<(), RuntimeErrorWithPosition> {
510511
if !call_sign.variadic && call_sign.num_params != arg_vals.len() {
511512
if let Expr::Identifier(ref id) = expr.data {
512-
return Err((RuntimeError::ArgumentLength(Some(id.clone())), expr.pos));
513+
return Err((RuntimeError::ArgumentLength(Some(id.clone())), full_expr.pos));
513514
}
514-
return Err((RuntimeError::ArgumentLength(None), expr.pos));
515+
return Err((RuntimeError::ArgumentLength(None), full_expr.pos));
515516
}
516517
Ok(())
517518
}

src/typechecker.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -611,22 +611,17 @@ impl TypeChecker {
611611
return Some(Type::Any);
612612
}
613613
v => {
614-
if let Expr::Identifier(ref id) = expr.data {
615-
self.issues
616-
.push((RuntimeError::CallToNonFunction(Some(id.clone()), v).into(),
617-
expr.pos));
618-
} else {
619-
self.issues
620-
.push((RuntimeError::CallToNonFunction(None, v).into(), expr.pos));
621-
}
614+
self.issues
615+
.push((RuntimeError::CallToNonFunction(try_get_name_of_fn(f_expr), v).into(),
616+
expr.pos));
622617
return Some(Type::Any);
623618
}
624619
};
625620

626621
let func_call_sign = func_type.get_call_sign();
627622
if !func_call_sign.variadic && args.len() != func_type.get_call_sign().num_params {
628623
self.issues
629-
.push((RuntimeError::ArgumentLength(try_get_name_of_fn(expr)).into(), expr.pos));
624+
.push((RuntimeError::ArgumentLength(try_get_name_of_fn(f_expr)).into(), expr.pos));
630625
return Some(Type::Any);
631626
}
632627
match func_type {

0 commit comments

Comments
 (0)