diff --git a/lib/Ast.ml b/lib/Ast.ml index 31a95ca8cc..522342075d 100644 --- a/lib/Ast.ml +++ b/lib/Ast.ml @@ -1220,12 +1220,18 @@ end = struct let check_bindings l = List.exists l ~f:(fun {pvb_pat; _} -> check_subpat pvb_pat) in - let check_function_param param = + let check_param_val (_, _, p) = p == pat in + let check_expr_function_param param = match param.pparam_desc with - | `Param_val (_, _, p) -> p == pat - | `Param_newtype _ -> false + | Param_val x -> check_param_val x + | Param_newtype _ -> false + in + let check_class_function_param param = + check_param_val param.pparam_desc + in + let check_class_function_params = + List.exists ~f:check_class_function_param in - let check_function_params l = List.exists l ~f:check_function_param in match ctx with | Pld (PPat (p1, _)) -> assert (p1 == pat) | Pld _ -> assert false @@ -1283,9 +1289,9 @@ end = struct | {pc_lhs; _} when pc_lhs == pat -> true | _ -> false ) ) | Pexp_for (p, _, _, _, _) -> assert (p == pat) - | Pexp_fun (p, _) -> assert (check_function_param p) ) - | Fpe ctx -> assert (check_function_param ctx) - | Fpc ctx -> assert (check_function_param ctx) + | Pexp_fun (p, _) -> assert (check_expr_function_param p) ) + | Fpe ctx -> assert (check_expr_function_param ctx) + | Fpc ctx -> assert (check_class_function_param ctx) | Vc _ -> assert false | Lb x -> assert (x.pvb_pat == pat) | Bo x -> assert (x.pbop_pat == pat) @@ -1294,7 +1300,7 @@ end = struct | Cl ctx -> assert ( match ctx.pcl_desc with - | Pcl_fun (p, _) -> check_function_params p + | Pcl_fun (p, _) -> check_class_function_params p | Pcl_constr _ -> false | Pcl_structure {pcstr_self; _} -> Option.exists ~f:(fun self_ -> self_ == pat) pcstr_self @@ -1336,12 +1342,18 @@ end = struct | PStr [{pstr_desc= Pstr_eval (e, _); _}] -> e == exp | _ -> false in - let check_function_param param = + let check_param_val (_, e, _) = Option.exists e ~f:(fun x -> x == exp) in + let check_expr_function_param param = match param.pparam_desc with - | `Param_val (_, e, _) -> Option.exists e ~f:(fun x -> x == exp) - | `Param_newtype _ -> false + | Param_val x -> check_param_val x + | Param_newtype _ -> false + in + let check_class_function_param param = + check_param_val param.pparam_desc + in + let check_class_function_params = + List.exists ~f:check_class_function_param in - let check_function_params l = List.exists l ~f:check_function_param in match ctx with | Pld (PPat (_, Some e1)) -> assert (e1 == exp) | Pld _ -> assert false @@ -1371,7 +1383,7 @@ end = struct | {pc_rhs; _} when pc_rhs == exp -> true | _ -> false ) ) | Pexp_fun (param, body) -> - assert (check_function_param param || body == exp) + assert (check_expr_function_param param || body == exp) | Pexp_indexop_access {pia_lhs; pia_kind= Builtin idx; pia_rhs; _} -> assert ( pia_lhs == exp || idx == exp @@ -1420,8 +1432,8 @@ end = struct | Pexp_for (_, e1, e2, _, e3) -> assert (e1 == exp || e2 == exp || e3 == exp) | Pexp_override e1N -> assert (List.exists e1N ~f:snd_f) ) - | Fpe ctx -> assert (check_function_param ctx) - | Fpc ctx -> assert (check_function_param ctx) + | Fpe ctx -> assert (check_expr_function_param ctx) + | Fpc ctx -> assert (check_class_function_param ctx) | Vc _ -> assert false | Lb x -> assert (x.pvb_expr == exp) | Bo x -> assert (x.pbop_exp == exp) @@ -1444,7 +1456,7 @@ end = struct | Cl ctx -> let rec loop ctx = match ctx.pcl_desc with - | Pcl_fun (param, e) -> check_function_params param || loop e + | Pcl_fun (param, e) -> check_class_function_params param || loop e | Pcl_constr _ -> false | Pcl_structure _ -> false | Pcl_apply (_, l) -> List.exists l ~f:(fun (_, e) -> e == exp) @@ -1889,8 +1901,8 @@ end = struct | Ppat_cons _ -> true | Ppat_construct _ | Ppat_record _ | Ppat_variant _ -> false | _ -> true ) - | Fpe {pparam_desc= `Param_val (_, _, _); _}, Ppat_cons _ -> true - | Fpc {pparam_desc= `Param_val (_, _, _); _}, Ppat_cons _ -> true + | Fpe {pparam_desc= Param_val (_, _, _); _}, Ppat_cons _ -> true + | Fpc {pparam_desc= _; _}, Ppat_cons _ -> true | Pat {ppat_desc= Ppat_construct _; _}, Ppat_cons _ -> true | _, Ppat_constraint (_, {ptyp_desc= Ptyp_poly _; _}) -> false | ( Exp {pexp_desc= Pexp_letop _; _} diff --git a/lib/Extended_ast.ml b/lib/Extended_ast.ml index 75ca950687..307543a223 100644 --- a/lib/Extended_ast.ml +++ b/lib/Extended_ast.ml @@ -235,18 +235,18 @@ module Parse = struct {p with pexp_desc= Pexp_pack (name, Some pt)} | { pexp_desc= Pexp_fun - ({pparam_desc= `Param_newtype types1; pparam_loc= loc1}, e1) + ({pparam_desc= Param_newtype types1; pparam_loc= loc1}, e1) ; pexp_attributes= [] ; _ } as e -> let e = match (expr m e1).pexp_desc with | Pexp_fun - ({pparam_desc= `Param_newtype types2; pparam_loc= loc2}, e2) + ({pparam_desc= Param_newtype types2; pparam_loc= loc2}, e2) -> { e with pexp_desc= Pexp_fun - ( { pparam_desc= `Param_newtype (types1 @ types2) + ( { pparam_desc= Param_newtype (types1 @ types2) ; pparam_loc= {loc1 with loc_end= loc2.loc_end} } , e2 ) } | _ -> e diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index 82785864ef..d39a838cfb 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -726,7 +726,7 @@ and type_constr_and_body c xbody = let exp_ctx = let pat = Ast_helper.Pat.any () in let param = - { pparam_desc= `Param_val (Nolabel, None, pat) + { pparam_desc= Param_val (Nolabel, None, pat) ; pparam_loc= pat.ppat_loc } in Exp Ast_helper.(Exp.fun_ param exp) @@ -1342,13 +1342,12 @@ and fmt_expr_fun_arg c fp = Cmts.fmt c fp.pparam_loc @@ match fp.pparam_desc with - | `Param_val x -> fmt_param_val c ctx x - | `Param_newtype x -> fmt_param_newtype c x + | Param_val x -> fmt_param_val c ctx x + | Param_newtype x -> fmt_param_newtype c x and fmt_class_fun_arg c fp = let ctx = Fpc fp in - Cmts.fmt c fp.pparam_loc - @@ match fp.pparam_desc with `Param_val x -> fmt_param_val c ctx x + Cmts.fmt c fp.pparam_loc @@ fmt_param_val c ctx fp.pparam_desc and fmt_expr_fun_args c args = list args "@;" (fmt_expr_fun_arg c) diff --git a/lib/Sugar.ml b/lib/Sugar.ml index 0c82ffb31a..3706d968a8 100644 --- a/lib/Sugar.ml +++ b/lib/Sugar.ml @@ -163,7 +163,7 @@ module Let_binding = struct [Extended_ast]. *) let pat = Ast_helper.Pat.any () in let param = - { pparam_desc= `Param_val (Nolabel, None, pat) + { pparam_desc= Param_val (Nolabel, None, pat) ; pparam_loc= pat.ppat_loc } in Exp (Ast_helper.Exp.fun_ param exp) diff --git a/vendor/parser-extended/ast_mapper.ml b/vendor/parser-extended/ast_mapper.ml index f81e954488..dcbb16dcf0 100644 --- a/vendor/parser-extended/ast_mapper.ml +++ b/vendor/parser-extended/ast_mapper.ml @@ -122,11 +122,10 @@ module FP = struct List.map (map_loc sub) ty let map_expr sub = function - | `Param_val x -> `Param_val (map_param_val sub x) - | `Param_newtype x -> `Param_newtype (map_param_newtype sub x) + | Param_val x -> Param_val (map_param_val sub x) + | Param_newtype x -> Param_newtype (map_param_newtype sub x) - let map_class sub = function - | `Param_val x -> `Param_val (map_param_val sub x) + let map_class sub x = map_param_val sub x let map sub f { pparam_loc; pparam_desc } = let pparam_loc = sub.location sub pparam_loc in diff --git a/vendor/parser-extended/parser.mly b/vendor/parser-extended/parser.mly index 5609f88eef..0feb64340e 100644 --- a/vendor/parser-extended/parser.mly +++ b/vendor/parser-extended/parser.mly @@ -2601,13 +2601,13 @@ param_newtype: ; expr_fun_param: mkfunparam( - param_val { `Param_val $1 } - | param_newtype { `Param_newtype $1 } + param_val { Param_val $1 } + | param_newtype { Param_newtype $1 } ) { $1 } ; class_fun_param: mkfunparam ( - param_val { `Param_val $1 } + param_val { $1 } ) { $1 } ; fun_def: diff --git a/vendor/parser-extended/parsetree.mli b/vendor/parser-extended/parsetree.mli index 4a8c269682..af612dcae1 100644 --- a/vendor/parser-extended/parsetree.mli +++ b/vendor/parser-extended/parsetree.mli @@ -506,10 +506,13 @@ and 'a function_param = pparam_desc : 'a; } -and expr_function_param = - [ `Param_val of param_val | `Param_newtype of param_newtype ] function_param +and param_val_or_newtype = + | Param_val of param_val + | Param_newtype of param_newtype -and class_function_param = [ `Param_val of param_val ] function_param +and expr_function_param = param_val_or_newtype function_param + +and class_function_param = param_val function_param and type_constraint = | Pconstraint of core_type diff --git a/vendor/parser-extended/printast.ml b/vendor/parser-extended/printast.ml index e494118afe..7ce7ee1848 100644 --- a/vendor/parser-extended/printast.ml +++ b/vendor/parser-extended/printast.ml @@ -525,13 +525,12 @@ and param_newtype i ppf ty = and expr_function_param i ppf { pparam_desc = desc; pparam_loc = loc } = line i ppf "function_param %a\n" fmt_location loc; match desc with - | `Param_val x -> param_val i ppf x - | `Param_newtype x -> param_newtype i ppf x + | Param_val x -> param_val i ppf x + | Param_newtype x -> param_newtype i ppf x and class_function_param i ppf { pparam_desc = desc; pparam_loc = loc } = line i ppf "function_param %a\n" fmt_location loc; - match desc with - | `Param_val x -> param_val i ppf x + param_val i ppf desc and type_constraint i ppf constraint_ = match constraint_ with