Skip to content

Commit 3d593ce

Browse files
committed
Make code more backward-compatible with existing ppxes
1 parent ec55da5 commit 3d593ce

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

ocaml/parsing/pprintast.ml

+10-7
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ and pp_print_pexp_function ctxt sep f x =
14241424
makes the pretty-printing a bit prettier. *)
14251425
match Jane_syntax.Expression.of_ast x with
14261426
| Some (Jexp_n_ary_function (params, c, body), []) ->
1427-
function_params_then_body ctxt f params c body ~delimiter:"="
1427+
function_params_then_body ctxt f params c body ~delimiter:sep
14281428
| Some (Jexp_layout (Lexp_newtype (str, lay, e)), []) ->
14291429
pp f "@[(type@ %s :@ %a)@]@ %a"
14301430
str.txt
@@ -1438,6 +1438,10 @@ and pp_print_pexp_function ctxt sep f x =
14381438
match x.pexp_desc with
14391439
| Pexp_newtype (str,e) ->
14401440
pp f "(type@ %s)@ %a" str.txt (pp_print_pexp_function ctxt sep) e
1441+
| Pexp_fun (a, b, c, body) ->
1442+
pp f "%a@;%a"
1443+
(label_exp ctxt) (a, b, c)
1444+
(pp_print_pexp_function ctxt sep) body
14411445
| _ ->
14421446
pp f "%s@;%a" sep (expression ctxt) x
14431447

@@ -2023,13 +2027,13 @@ and function_constraint
20232027
(core_type ctxt) ty2
20242028

20252029
and function_params_then_body ctxt f params constraint_ body ~delimiter =
2026-
let pp_params f () =
2030+
let pp_params f =
20272031
match params with
20282032
| [] -> ()
20292033
| _ :: _ -> pp f "%a@;" (list (function_param ctxt) ~sep:"@ ") params
20302034
in
2031-
pp f "%a%a%s@;%a"
2032-
pp_params ()
2035+
pp f "%t%a%s@;%a"
2036+
pp_params
20332037
(option (function_constraint ctxt) ~first:"@;") constraint_
20342038
delimiter
20352039
(function_body (under_functionrhs ctxt)) body
@@ -2057,11 +2061,10 @@ and n_ary_function_expr
20572061
(function_body ctxt) body
20582062
(function_constraint ctxt) constraint_
20592063
| _ :: _, _ ->
2060-
pp f "@[<2>fun@;%a@]"
2061-
(fun f () ->
2064+
pp f "@[<2>fun@;%t@]"
2065+
(fun f ->
20622066
function_params_then_body
20632067
ctxt f params constraint_ body ~delimiter:"->")
2064-
()
20652068

20662069
let toplevel_phrase f x =
20672070
match x with

ocaml/typing/typecore.ml

+12-4
Original file line numberDiff line numberDiff line change
@@ -3756,10 +3756,18 @@ let rec type_approx env sexp ty_expected =
37563756
| Some (jexp, _attrs) -> type_approx_aux_jane_syntax ~loc env jexp ty_expected
37573757
| None -> match sexp.pexp_desc with
37583758
Pexp_let (_, _, e) -> type_approx env e ty_expected
3759-
| Pexp_fun _ ->
3760-
Misc.fatal_error "[type_approx] didn't expect [Pexp_fun]"
3761-
| Pexp_function _ ->
3762-
Misc.fatal_error "[type_approx] didn't expect [Pexp_function]"
3759+
| Pexp_fun (lbl, def, pat, body) ->
3760+
let open Jane_syntax.N_ary_functions in
3761+
type_approx_function ~loc env
3762+
[ { pparam_desc = Pparam_val (lbl, def, pat);
3763+
pparam_loc = pat.ppat_loc
3764+
}
3765+
]
3766+
None (Pfunction_body body) ty_expected
3767+
| Pexp_function cases ->
3768+
let open Jane_syntax.N_ary_functions in
3769+
type_approx_function ~loc
3770+
env [] None (Pfunction_cases (cases, sexp.pexp_loc, [])) ty_expected
37633771
| Pexp_match (_, {pc_rhs=e}::_) -> type_approx env e ty_expected
37643772
| Pexp_try (e, _) -> type_approx env e ty_expected
37653773
| Pexp_tuple l ->

0 commit comments

Comments
 (0)