X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;ds=sidebyside;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_semant.ml;h=21816959a1ab402b4f736c3d27cf15f73f06d5e6;hb=9340b0e333dd6acb5b18f68d1bf3eadad8401fa5;hp=8d0ca11a4d8c6afadcc92a7bcf743b46a51e10f1;hpb=cbb4ffb6428f52eaea42f6039332af0c392cdd0f;p=tiger.ml.git diff --git a/compiler/src/lib/tiger/tiger_semant.ml b/compiler/src/lib/tiger/tiger_semant.ml index 8d0ca11..2181695 100644 --- a/compiler/src/lib/tiger/tiger_semant.ml +++ b/compiler/src/lib/tiger/tiger_semant.ml @@ -3,7 +3,6 @@ module List = ListLabels module A = Tiger_absyn module Env = Tiger_env module E = Tiger_error -module Symbol = Tiger_symbol module Translate = Tiger_translate module Type = Tiger_env_type module Value = Tiger_env_value @@ -90,10 +89,20 @@ end = struct | A.CallExp {func; args; pos} -> (match env_get_val ~sym:func ~env ~pos with | Value.Fun {formals; result} -> - List.iter2 formals args ~f:(fun ty_expected exp_given -> - check_same (return (actual_ty ~pos ty_expected)) (trexp exp_given) ~pos; - ); - return (actual_ty ~pos result) + let expected = List.length formals in + let given = List.length args in + if given = expected then + begin + List.iter2 formals args ~f:(fun ty_expected exp_given -> + check_same + (return (actual_ty ~pos ty_expected)) + (trexp exp_given) + ~pos; + ); + return (actual_ty ~pos result) + end + else + E.raise (E.Wrong_number_of_args {func; expected; given; pos}) | Value.Var _ -> E.raise (E.Id_not_a_function {id=func; pos}) ) @@ -285,7 +294,7 @@ end = struct List.iter typedecs ~f:(fun (A.TypeDec {name; ty=ty_exp; pos}) -> let ty = transTy ~env ty_exp in (match env_get_typ ~sym:name ~env ~pos with - | Type.Name (name, ty_opt_ref) -> + | Type.Name (_, ty_opt_ref) -> ty_opt_ref := Some ty | Type.Unit | Type.Nil