Skip to content

Commit

Permalink
Merge pull request #690 from vsbogd/fix-type-error-name
Browse files Browse the repository at this point in the history
Fix incorrect number of arguments type error constant
  • Loading branch information
vsbogd authored May 8, 2024
2 parents b964a2d + 2ac1c16 commit e7c42b6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/src/metta/runner/stdlib_minimal.metta
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 30 additions & 5 deletions lib/src/metta/runner/stdlib_minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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![]]));
Expand Down

0 comments on commit e7c42b6

Please sign in to comment.