Skip to content

Commit

Permalink
Fix ord variant wildcard_case to_int type pre-OCaml 4.11 (PR #260)
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Mar 19, 2022
1 parent 6eb5745 commit c2c4bc4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src_plugins/ord/ppx_deriving_ord.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ let reduce_compare l =

let wildcard_case ~typ int_cases =
let loc = !Ast_helper.default_loc in
let to_int_fun = [%expr fun (x: [%t typ]) -> [%e Exp.match_ [%expr x] int_cases]] in
(* Need explicit polymorphic type for pre-OCaml 4.11 compatibility,
but just using Ppx_deriving.strong_type_of_type doesn't work,
so adding explicit polymorphism using (type a) arguments instead.
See: https://github.com/ocaml-ppx/ppx_deriving/pull/260#issuecomment-1072995847. *)
let free_vars = Ppx_deriving.free_vars_in_core_type typ in
let poly_to_int_fun = List.fold_right Exp.newtype free_vars to_int_fun in
Exp.case [%pat? _] [%expr
let to_int: [%t typ] -> Ppx_deriving_runtime.int = [%e Exp.function_ int_cases] in
let to_int = [%e poly_to_int_fun] in
Ppx_deriving_runtime.compare (to_int lhs) (to_int rhs)]

let pattn side typs =
Expand Down

0 comments on commit c2c4bc4

Please sign in to comment.