| Different_operand_types _ ->
false
+let is_wrong_number_of_args t =
+ match t with
+ | Wrong_number_of_args _ ->
+ true
+ | Wrong_type _
+ | Unknown_type _
+ | Unknown_id _
+ | Invalid_syntax _
+ | Id_is_a_function _
+ | Id_not_a_function _
+ | No_such_field_in_record _
+ | Exp_not_a_record _
+ | Exp_not_an_array _
+ | Wrong_type_of_expression_in_var_dec _
+ | Wrong_type_used_as_array _
+ | Wrong_type_used_as_record _
+ | Wrong_type_of_field_value _
+ | Wrong_type_of_arg _
+ | Invalid_operand_type _
+ | Different_operand_types _ ->
+ false
+
let is_invalid_syntax t =
match t with
| Invalid_syntax _ ->
val is_unknown_id : t -> bool
val is_unknown_type : t -> bool
val is_wrong_type : t -> bool
+val is_wrong_number_of_args : t -> bool
val is_invalid_syntax : t -> bool
val is_not_a_record : t -> bool
val is_not_an_array : t -> bool
| 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})
)
| "test25.tig" ->
Some Error.is_not_a_record
(* TODO: Be more specific *)
+ | "test35.tig"
+ | "test36.tig" ->
+ Some Error.is_wrong_number_of_args
+ (* TODO: Be more specific - how many expected, how many given? *)
| "test09.tig"
| "test11.tig"
| "test13.tig"