diff --git a/dune-project b/dune-project index 4f31a1b..f7b4053 100755 --- a/dune-project +++ b/dune-project @@ -34,7 +34,7 @@ landmarks library.") (depends (ocaml (>= 4.08)) - (ppxlib (>= 0.22)) + (ppxlib (>= 0.36)) (landmarks (= 1.5)) ) ) diff --git a/landmarks-ppx.opam b/landmarks-ppx.opam index bb2ab4c..e7e531a 100644 --- a/landmarks-ppx.opam +++ b/landmarks-ppx.opam @@ -13,7 +13,7 @@ bug-reports: "https://github.com/LexiFi/landmarks/issues" depends: [ "dune" {>= "3.16"} "ocaml" {>= "4.08"} - "ppxlib" {>= "0.22"} + "ppxlib" {>= "0.36"} "landmarks" {= "1.5"} "odoc" {with-doc} ] diff --git a/ppx/mapper.ml b/ppx/mapper.ml index 2456126..879c0e1 100644 --- a/ppx/mapper.ml +++ b/ppx/mapper.ml @@ -176,17 +176,26 @@ let wrap_landmark ctx landmark loc expr = let rec arity {pexp_desc; _} = match pexp_desc with - | Pexp_fun (a, _, _, e) -> a :: arity e - | Pexp_function cases -> - let max_list l1 l2 = - if List.length l1 < List.length l2 then - l1 - else - l2 - in - Nolabel :: (List.fold_left - (fun acc {pc_rhs; _} -> max_list (arity pc_rhs) acc) - [] cases) + | Pexp_function (param_list, _, body) -> + let body_arity = + match body with + | Pfunction_body e -> arity e + | Pfunction_cases (cases, _, _) -> + let max_list l1 l2 = + if List.length l1 < List.length l2 then + l1 + else + l2 + in + Nolabel :: (List.fold_left + (fun acc {pc_rhs; _} -> max_list (arity pc_rhs) acc) + [] cases) + in + List.fold_right (fun param acc -> + match param.pparam_desc with + | Pparam_val (arg_label, _, _) -> arg_label :: acc + | Pparam_newtype _ -> acc + ) param_list body_arity | Pexp_newtype (_, e) -> arity e | Pexp_constraint (e, _) -> arity e | Pexp_poly (e, _) -> arity e @@ -194,8 +203,9 @@ let rec arity {pexp_desc; _} = let rec wrap_landmark_method ctx landmark loc ({pexp_desc; _} as expr) = match pexp_desc with - | Pexp_fun (label, def, pat, e) -> - { expr with pexp_desc = Pexp_fun (label, def, pat, wrap_landmark_method ctx landmark loc e)} + | Pexp_function (param_list, tc_opt, Pfunction_body e) -> + { expr with pexp_desc = Pexp_function (param_list, tc_opt, + Pfunction_body (wrap_landmark_method ctx landmark loc e)) } | Pexp_poly (e, typ) -> { expr with pexp_desc = Pexp_poly (wrap_landmark_method ctx landmark loc e, typ)} | _ -> wrap_landmark ctx landmark loc expr @@ -256,10 +266,10 @@ let translate_value_bindings ctx value_binding auto vbs = in let vbs = List.map (function | (vb, None) -> value_binding vb - | {pvb_pat; pvb_loc; pvb_expr; _}, Some (arity, _, name, loc, attrs) -> + | {pvb_pat; pvb_loc; pvb_expr; pvb_constraint; _}, Some (arity, _, name, loc, attrs) -> (* Remove landmark attribute: *) let vb = - Vb.mk ~attrs ~loc:pvb_loc pvb_pat pvb_expr + Vb.mk ~attrs ~loc:pvb_loc ?value_constraint:pvb_constraint pvb_pat pvb_expr |> value_binding in if arity = [] then