Skip to content

Commit 1638744

Browse files
committed
Fix formatting of Ptyp_poly in other contextes
1 parent dc32d7b commit 1638744

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

lib/Fmt_ast.ml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ and fmt_arrow_type c ~ctx ?indent ~parens ~parent_has_parens args fmt_ret_typ
833833
of the expression, i.e. if the expression is part of a `fun`
834834
expression. *)
835835
and fmt_core_type c ?(box = true) ?pro ?(pro_space = true) ?constraint_ctx
836-
({ast= typ; ctx} as xtyp) =
836+
({ast= typ; ctx= ctx0} as xtyp) =
837837
protect c (Typ typ)
838838
@@
839839
let {ptyp_desc; ptyp_attributes; ptyp_loc; _} = typ in
@@ -858,7 +858,7 @@ and fmt_core_type c ?(box = true) ?pro ?(pro_space = true) ?constraint_ctx
858858
c.conf
859859
@@
860860
let in_type_declaration =
861-
match ctx with
861+
match ctx0 with
862862
| Td {ptype_manifest= Some t; _} -> phys_equal t typ
863863
| _ -> false
864864
in
@@ -922,23 +922,26 @@ and fmt_core_type c ?(box = true) ?pro ?(pro_space = true) ?constraint_ctx
922922
| Ptyp_poly ([], _) ->
923923
impossible "produced by the parser, handled elsewhere"
924924
| Ptyp_poly (a1N, t) ->
925-
let break, pro =
925+
let ctx_is_value_constraint = function Vc _ -> true | _ -> false in
926+
let break, box_core_type =
926927
match
927928
(c.conf.fmt_opts.break_separators.v, c.conf.fmt_opts.break_colon.v)
928929
with
929-
| `Before, `Before ->
930+
| `Before, `Before when ctx_is_value_constraint ctx0 ->
931+
(* Special formatting for leading [->] in let bindings. *)
930932
let indent =
931933
match t.ptyp_desc with Ptyp_arrow _ -> 3 | _ -> 2
932934
in
933-
(break 1 indent, None)
935+
(break 1 indent, Some false)
934936
| _ -> (space_break, None)
935937
in
936938
hovbox_if box 0
937939
( hovbox 0
938940
( list a1N space_break (fun {txt; _} -> fmt_type_var txt)
939941
$ str "." )
940942
$ break
941-
$ fmt_core_type c ~box ?pro ~pro_space:false (sub_typ ~ctx t) )
943+
$ fmt_core_type c ?box:box_core_type ~pro_space:false
944+
(sub_typ ~ctx t) )
942945
| Ptyp_tuple typs ->
943946
hvbox 0
944947
(wrap_if parenze_constraint_ctx (str "(") (str ")")

test/passing/tests/js_source.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8249,3 +8249,13 @@ let _ =
82498249
fun id -> not (Ident.HashQueue.mem q id)
82508250
| None -> fun id -> not (List.mem ~equal:Ident.equal ids id)
82518251
;;
8252+
8253+
type callbacks =
8254+
{ html_debug_new_node_session_f :
8255+
'a.
8256+
?kind:[ `ComputePre | `ExecNode | `ExecNodeNarrowing | `WTO ]
8257+
-> pp_name:(Format.formatter -> unit)
8258+
-> Procdesc.Node.t
8259+
-> f:(unit -> 'a)
8260+
-> 'a
8261+
}

test/passing/tests/js_source.ml.ocp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10537,3 +10537,13 @@ let _ =
1053710537
fun id -> not (Ident.HashQueue.mem q id)
1053810538
| None -> fun id -> not (List.mem ~equal:Ident.equal ids id)
1053910539
;;
10540+
10541+
type callbacks =
10542+
{ html_debug_new_node_session_f :
10543+
'a.
10544+
?kind:[ `ComputePre | `ExecNode | `ExecNodeNarrowing | `WTO ]
10545+
-> pp_name:(Format.formatter -> unit)
10546+
-> Procdesc.Node.t
10547+
-> f:(unit -> 'a)
10548+
-> 'a
10549+
}

test/passing/tests/js_source.ml.ref

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10537,3 +10537,13 @@ let _ =
1053710537
fun id -> not (Ident.HashQueue.mem q id)
1053810538
| None -> fun id -> not (List.mem ~equal:Ident.equal ids id)
1053910539
;;
10540+
10541+
type callbacks =
10542+
{ html_debug_new_node_session_f :
10543+
'a.
10544+
?kind:[ `ComputePre | `ExecNode | `ExecNodeNarrowing | `WTO ]
10545+
-> pp_name:(Format.formatter -> unit)
10546+
-> Procdesc.Node.t
10547+
-> f:(unit -> 'a)
10548+
-> 'a
10549+
}

0 commit comments

Comments
 (0)