Fix bug where only first type of argument checked

This commit is contained in:
백현웅 2022-02-23 02:45:11 +09:00
parent a0791f97ad
commit 74a4af9c33

25
eval.ml
View file

@ -241,18 +241,25 @@ module External = struct
end
let find_operator op ts =
let filter t =
List.filter (fun (ts, _) ->
match ts with [] -> false | x::_ -> t=x)
let open List in
let filter_type t i =
filter (fun (ts, _) ->
nth_opt ts i
|> Option.map ((=) t)
|> Option.value ~default: false)
in
let rec aux ops = function
| [] -> List.nth_opt ops 0
let rec aux ops i = function
| [] ->
ops
|> filter (fun (ts, _) -> length ts = i)
|> Fun.flip nth_opt 0
| t::ts ->
(match aux (filter t ops) ts with
| None -> Option.bind (Type.supertype t) (fun t -> aux ops (t::ts))
| Some _ as x -> x)
(match aux (filter_type t i ops) (i+1) ts with
| None -> Option.bind (Type.supertype t)
(fun t -> aux ops i (t::ts))
| Some _ as x -> x)
in
aux (Operator.get op) ts
aux (Operator.get op) 0 ts
let promote_values =
let rec promote_until t v =