Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for 5.2 AST bump #299

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/ppx/uncurried_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ let wrap_core_type_uncurried ?(arity = 1) typ =
| false -> typ
| true -> ctyp_arrow ~loc:typ.ptyp_loc ~arity typ

let rec determine_arity_params acc = function
| { pparam_desc = Pparam_val _; _ } :: rest -> determine_arity_params (acc + 1) rest
| { pparam_desc = Pparam_newtype _; _} :: rest -> determine_arity_params acc rest
| [] -> acc

let rec determineArity ~arity expr =
match expr.pexp_desc with
| Pexp_fun (_, _, _, fn) -> determineArity ~arity:(arity + 1) fn
| Pexp_function (params, _constraint, Pfunction_body fn) -> determineArity ~arity:(arity + determine_arity_params 0 params) fn
| Pexp_function (params, _constraint, Pfunction_cases _) -> arity + determine_arity_params 0 params
| _ -> arity

let wrap_as_uncurried_vb ?(arity = 1) item =
match (Ppx_config.uncurried (), item) with
| false, _ -> item
| _, ({ pvb_expr = { pexp_desc = Pexp_fun _ } as fn } as outerV) ->
| _, ({ pvb_expr = { pexp_desc = Pexp_function (_ :: _, _, _) } as fn } as outerV) ->
{
outerV with
pvb_expr = function_expression_uncurried ~loc:outerV.pvb_loc ~arity fn;
Expand All @@ -81,7 +87,7 @@ let wrap_as_uncurried_fn_multi ?(arity = 1) item =
let new_value_bindings =
value_bindings
|> List.map (function
| { pvb_expr = { pexp_desc = Pexp_fun _ } as fn } as outerV ->
| { pvb_expr = { pexp_desc = Pexp_function (_ :: _, _, _) } as fn } as outerV ->
{
outerV with
pvb_expr =
Expand Down Expand Up @@ -119,7 +125,7 @@ let wrap_sig_uncurried_fn ?(arity = 1) item =
let handle_str_item item =
match item.pstr_desc with
| Pstr_value
(a1, [ ({ pvb_expr = { pexp_desc = Pexp_fun _ } as fn } as outerV) ]) ->
(a1, [ ({ pvb_expr = { pexp_desc = Pexp_function (_ :: _, _, _) } as fn } as outerV) ]) ->
{
item with
pstr_desc =
Expand Down