handle args count
This commit is contained in:
parent
5b915a88e8
commit
c0c8880c56
3 changed files with 23 additions and 0 deletions
|
@ -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
|
||||
|
|
7
tests/14_err-too-much-args.test
Normal file
7
tests/14_err-too-much-args.test
Normal file
|
@ -0,0 +1,7 @@
|
|||
int foo (int a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
void main () {
|
||||
foo(13, 12);
|
||||
}
|
7
tests/15_err-args-missing.test
Normal file
7
tests/15_err-args-missing.test
Normal file
|
@ -0,0 +1,7 @@
|
|||
int foo (int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
void main () {
|
||||
foo(42);
|
||||
}
|
Reference in a new issue