diff options
Diffstat (limited to 'syntax/type_of.ml')
-rw-r--r-- | syntax/type_of.ml | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/syntax/type_of.ml b/syntax/type_of.ml index a9e1e79..6faea62 100644 --- a/syntax/type_of.ml +++ b/syntax/type_of.ml @@ -34,12 +34,13 @@ module Helper = struct type argument = Fixed of t | Dynamic of dyn_type | Variable of argument let compare : + ?strict:bool -> ?level:Report.level -> t -> argument_repr -> Report.t list -> Report.t list = - fun ?(level = Report.Warn) expected actual report -> + fun ?(strict = false) ?(level = Report.Warn) expected actual report -> let equal = match (expected, actual.t) with | _, Any -> true @@ -47,11 +48,11 @@ module Helper = struct | String, String -> true | Integer, Integer -> true | Bool, Bool -> true - | Bool, Integer -> true + | Bool, Integer when not strict -> true | Integer, Bool -> true - | String, Integer -> true - | String, Bool -> true - | _, String -> false + | String, Integer when not strict -> true + | String, Bool when not strict -> true + | _, _ -> false in if equal then report else @@ -62,37 +63,39 @@ module Helper = struct Report.message level actual.pos message :: report let rec compare_parameter : + ?strict:bool -> ?level:Report.level -> argument -> argument_repr -> Report.t list -> Report.t list = - fun ?(level = Report.Warn) expected param report -> + fun ?(strict = false) ?(level = Report.Warn) expected param report -> match expected with | Fixed t -> compare ~level t param report | Dynamic d -> let type_ = d param.t in - compare ~level type_ param report + compare ~strict ~level type_ param report | Variable c -> compare_parameter ~level c param report (** Compare the arguments one by one *) let compare_args : + ?strict:bool -> ?level:Report.level -> pos -> argument list -> argument_repr list -> Report.t list -> Report.t list = - fun ?(level = Report.Warn) pos expected actuals report -> + fun ?(strict = false) ?(level = Report.Warn) pos expected actuals report -> let tl, report = List.fold_left actuals ~init:(expected, report) ~f:(fun (expected, report) param -> match expected with | (Variable _ as hd) :: _ -> - let check = compare_parameter ~level hd param report in + let check = compare_parameter ~strict ~level hd param report in (expected, check) | hd :: tl -> - let check = compare_parameter ~level hd param report in + let check = compare_parameter ~strict ~level hd param report in (tl, check) | [] -> let msg = Report.error param.pos "Unexpected argument" in @@ -256,10 +259,11 @@ module Expression = struct match operator with | T.Plus -> (* Operation over number *) - let d = Helper.(Dynamic (dyn_type ())) in - let expected = [ d; d ] in + let d = Helper.(dyn_type ()) in + let expected = Helper.[ Dynamic d; Dynamic d ] in let report = Helper.compare_args pos expected types report in - { result = Bool; report; pos; empty = false } + let result = d Helper.Integer in + { result; report; pos; empty = false } | T.Eq | T.Neq -> (* If the expression is '' or 0, we accept the comparaison as if instead of raising a warning *) @@ -269,7 +273,8 @@ module Expression = struct let d = Helper.(Dynamic (dyn_type ())) in let expected = [ d; d ] in let report = - Helper.compare_args pos expected (List.rev types) report + Helper.compare_args ~strict:true pos expected (List.rev types) + report in { result = Bool; report; pos; empty = false } | Lt | Gte | Lte | Gt -> |