diff --git a/semantics.ml b/semantics.ml index 67ec0c2..dae0e21 100644 --- a/semantics.ml +++ b/semantics.ml @@ -25,6 +25,15 @@ let rec analyze_expr env ua t = function (match Env.find c.func env with | Func_t (ret_t, tl) -> if ret_t != t then errt ret_t t c.pos; + if List.length tl != List.length c.args + then + raise + (SemanticsError + ( Printf.sprintf + "Expected %d arguments but given %d" + (List.length tl) + (List.length c.args) + , c.pos )); ( Call ( c.func , List.map2 diff --git a/tests/14_err-too-much-args.test b/tests/14_err-too-much-args.test new file mode 100644 index 0000000..8770027 --- /dev/null +++ b/tests/14_err-too-much-args.test @@ -0,0 +1,7 @@ +int foo (int a) { + return a; +} + +void main () { + foo(13, 12); +} diff --git a/tests/15_err-args-missing.test b/tests/15_err-args-missing.test new file mode 100644 index 0000000..7c4e86f --- /dev/null +++ b/tests/15_err-args-missing.test @@ -0,0 +1,7 @@ +int foo (int a, int b) { + return a + b; +} + +void main () { + foo(42); +}