From c0c8880c56e5267b1313539f91aeee057a30ac65 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 10 Dec 2022 16:11:37 +0100 Subject: [PATCH] handle args count --- semantics.ml | 9 +++++++++ tests/14_err-too-much-args.test | 7 +++++++ tests/15_err-args-missing.test | 7 +++++++ 3 files changed, 23 insertions(+) create mode 100644 tests/14_err-too-much-args.test create mode 100644 tests/15_err-args-missing.test 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); +}