@@ -752,18 +752,19 @@ and fmt_type_cstr c ?(pro = ":") ?constraint_ctx xtyp =
752752 let colon_before = Poly. (c.conf.fmt_opts.break_colon.v = `Before ) in
753753 let wrap, inner_pro, box =
754754 match xtyp.ast.ptyp_desc with
755- | (Ptyp_poly (_, {ptyp_desc= Ptyp_arrow _; _}) | Ptyp_arrow _)
756- when colon_before ->
755+ | (Ptyp_poly _ | Ptyp_arrow _ ) when colon_before ->
757756 let outer_pro =
758- if c.conf.fmt_opts.ocp_indent_compat.v then
759- fits_breaks (pro ^ " " ) (pro ^ " " )
760- else str pro $ str " "
757+ match (xtyp.ast.ptyp_desc, c.conf.fmt_opts.break_separators.v) with
758+ | ( (Ptyp_poly (_, {ptyp_desc= Ptyp_arrow _; _}) | Ptyp_arrow _)
759+ , `Before ) ->
760+ fits_breaks (pro ^ " " ) (pro ^ " " )
761+ | _ -> str pro $ str " "
761762 in
762763 let pre_break =
763764 if colon_before then fits_breaks " " ~hint: (1000 , 0 ) " "
764765 else break 0 ~- 1
765766 in
766- let wrap x = pre_break $ cbox 0 (outer_pro $ x) in
767+ let wrap x = pre_break $ hvbox 0 (outer_pro $ x) in
767768 (wrap, None , false )
768769 | _ ->
769770 ( (fun k ->
@@ -832,7 +833,7 @@ and fmt_arrow_type c ~ctx ?indent ~parens ~parent_has_parens args fmt_ret_typ
832833 of the expression, i.e. if the expression is part of a `fun`
833834 expression. *)
834835and fmt_core_type c ?(box = true ) ?pro ?(pro_space = true ) ?constraint_ctx
835- ({ast = typ ; ctx} as xtyp ) =
836+ ({ast = typ ; ctx = ctx0 } as xtyp ) =
836837 protect c (Typ typ)
837838 @@
838839 let {ptyp_desc; ptyp_attributes; ptyp_loc; _} = typ in
@@ -857,7 +858,7 @@ and fmt_core_type c ?(box = true) ?pro ?(pro_space = true) ?constraint_ctx
857858 c.conf
858859 @@
859860 let in_type_declaration =
860- match ctx with
861+ match ctx0 with
861862 | Td {ptype_manifest = Some t ; _} -> phys_equal t typ
862863 | _ -> false
863864 in
@@ -921,10 +922,26 @@ and fmt_core_type c ?(box = true) ?pro ?(pro_space = true) ?constraint_ctx
921922 | Ptyp_poly ([] , _ ) ->
922923 impossible " produced by the parser, handled elsewhere"
923924 | Ptyp_poly (a1N , t ) ->
925+ let ctx_is_value_constraint = function Vc _ -> true | _ -> false in
926+ let break, box_core_type =
927+ match
928+ (c.conf.fmt_opts.break_separators.v, c.conf.fmt_opts.break_colon.v)
929+ with
930+ | `Before , `Before when ctx_is_value_constraint ctx0 ->
931+ (* Special formatting for leading [->] in let bindings. *)
932+ let indent =
933+ match t.ptyp_desc with Ptyp_arrow _ -> 3 | _ -> 2
934+ in
935+ (break 1 indent, Some false )
936+ | _ -> (space_break, None )
937+ in
924938 hovbox_if box 0
925- ( list a1N space_break (fun {txt; _} -> fmt_type_var txt)
926- $ str " ." $ space_break
927- $ fmt_core_type c ~box: true (sub_typ ~ctx t) )
939+ ( hovbox 0
940+ ( list a1N space_break (fun {txt; _} -> fmt_type_var txt)
941+ $ str " ." )
942+ $ break
943+ $ fmt_core_type c ?box:box_core_type ~pro_space: false
944+ (sub_typ ~ctx t) )
928945 | Ptyp_tuple typs ->
929946 hvbox 0
930947 (wrap_if parenze_constraint_ctx (str " (" ) (str " )" )
@@ -1509,7 +1526,7 @@ and fmt_function ?(last_arg = false) ?force_closing_paren ~ctx ~ctx0
15091526 let head = fmt_fun_args_typ args typ in
15101527 let body ~pro = pro $ fmt_expression c (sub_exp ~ctx body) in
15111528 let box, closing_paren_offset =
1512- Params.Exp. box_fun_expr c.conf ~source: c.source ~ctx0 ~ctx ~parens
1529+ Params.Exp. box_fun_expr c.conf ~source: c.source ~ctx0 ~ctx
15131530 in
15141531 let closing_paren_offset =
15151532 if should_box then closing_paren_offset else ~- 2
0 commit comments