diff --git a/lib/src/metta/runner/stdlib_minimal.metta b/lib/src/metta/runner/stdlib_minimal.metta index b40442332..0c5061e9f 100644 --- a/lib/src/metta/runner/stdlib_minimal.metta +++ b/lib/src/metta/runner/stdlib_minimal.metta @@ -212,8 +212,8 @@ (eval (match-types $actual-ret-type $ret-type (return ()) (return (Error $atom BadType)) )) - (return (Error $atom BadType)) ))) - (return (Error $atom "Too many arguments")) )) + (return (Error $atom IncorrectNumberOfArguments)) ))) + (return (Error $atom IncorrectNumberOfArguments)) )) (eval (if-decons-expr $args $head $tail (eval (if-decons-expr $arg-types $head-type $tail-types (chain (eval (interpret $head $head-type $space)) $reduced-head diff --git a/lib/src/metta/runner/stdlib_minimal.rs b/lib/src/metta/runner/stdlib_minimal.rs index 08f6feb63..54bcba1f6 100644 --- a/lib/src/metta/runner/stdlib_minimal.rs +++ b/lib/src/metta/runner/stdlib_minimal.rs @@ -753,11 +753,6 @@ mod tests { !(eval (interpret (Cons S (Cons Z Nil)) %Undefined% &self)) "); assert_eq!(result, Ok(vec![vec![expr!("Error" ("Cons" "Z" "Nil") "BadType")]])); - let result = run_program(" - (: foo (-> Atom Atom Atom)) - !(eval (interpret (foo A) %Undefined% &self)) - "); - assert_eq!(result, Ok(vec![vec![expr!("Error" ("foo" "A") "BadType")]])); } #[test] @@ -1038,6 +1033,36 @@ mod tests { Ok(vec![vec![expr!("Error" "myAtom" "BadType")]])); } + #[test] + fn test_return_incorrect_number_of_args_error() { + let program1 = " + (: a A) + (: b B) + (: c C) + (: foo (-> A B C)) + (= (foo $a $b) c) + + !(eval (interpret (foo a b) %Undefined% &self)) + "; + + let metta = Metta::new(Some(EnvBuilder::test_env())); + metta.tokenizer().borrow_mut().register_token(Regex::new("id_num").unwrap(), + |_| Atom::gnd(ID_NUM)); + + assert_eq!(metta.run(SExprParser::new(program1)), + Ok(vec![vec![expr!("c")]])); + + let program2 = "!(eval (interpret (foo a) %Undefined% &self))"; + + assert_eq!(metta.run(SExprParser::new(program2)), + Ok(vec![vec![expr!("Error" ("foo" "a") "IncorrectNumberOfArguments")]])); + + let program3 = "!(eval (interpret (foo a b c) %Undefined% &self))"; + + assert_eq!(metta.run(SExprParser::new(program3)), + Ok(vec![vec![expr!("Error" ("foo" "a" "b" "c") "IncorrectNumberOfArguments")]])); + } + #[test] fn use_sealed_to_make_scoped_variable() { assert_eq!(run_program("!(let $x (input $x) (output $x))"), Ok(vec![vec![]]));