@@ -104379,6 +104379,7 @@ module Res_parsetree_viewer : sig
104379
104379
* The parsetree contains: a => b => c => d, for printing purposes
104380
104380
* we restructure the tree into (a, b, c) and its returnType d *)
104381
104381
val arrowType :
104382
+ ?arity:int ->
104382
104383
Parsetree.core_type ->
104383
104384
Parsetree.attributes
104384
104385
* (Parsetree.attributes * Asttypes.arg_label * Parsetree.core_type) list
@@ -104535,15 +104536,16 @@ end = struct
104535
104536
#1 "res_parsetree_viewer.ml"
104536
104537
open Parsetree
104537
104538
104538
- let arrowType ct =
104539
- let rec process attrsBefore acc typ =
104539
+ let arrowType ?(arity = max_int) ct =
104540
+ let rec process attrsBefore acc typ arity =
104540
104541
match typ with
104542
+ | typ when arity <= 0 -> (attrsBefore, List.rev acc, typ)
104541
104543
| {
104542
104544
ptyp_desc = Ptyp_arrow ((Nolabel as lbl), typ1, typ2);
104543
104545
ptyp_attributes = [];
104544
104546
} ->
104545
104547
let arg = ([], lbl, typ1) in
104546
- process attrsBefore (arg :: acc) typ2
104548
+ process attrsBefore (arg :: acc) typ2 (arity - 1)
104547
104549
| {
104548
104550
ptyp_desc = Ptyp_arrow (Nolabel, _typ1, _typ2);
104549
104551
ptyp_attributes = [({txt = "bs"}, _)];
@@ -104560,14 +104562,14 @@ let arrowType ct =
104560
104562
ptyp_attributes = attrs;
104561
104563
} ->
104562
104564
let arg = (attrs, lbl, typ1) in
104563
- process attrsBefore (arg :: acc) typ2
104565
+ process attrsBefore (arg :: acc) typ2 (arity - 1)
104564
104566
| typ -> (attrsBefore, List.rev acc, typ)
104565
104567
in
104566
104568
match ct with
104567
104569
| {ptyp_desc = Ptyp_arrow (Nolabel, _typ1, _typ2); ptyp_attributes = attrs} as
104568
104570
typ ->
104569
- process attrs [] {typ with ptyp_attributes = []}
104570
- | typ -> process [] [] typ
104571
+ process attrs [] {typ with ptyp_attributes = []} arity
104572
+ | typ -> process [] [] typ arity
104571
104573
104572
104574
let functorType modtype =
104573
104575
let rec process acc modtype =
@@ -109607,8 +109609,10 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =
109607
109609
])
109608
109610
109609
109611
and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
109610
- let printArrow ~uncurried typExpr =
109611
- let attrsBefore, args, returnType = ParsetreeViewer.arrowType typExpr in
109612
+ let printArrow ~uncurried ?(arity = max_int) typExpr =
109613
+ let attrsBefore, args, returnType =
109614
+ ParsetreeViewer.arrowType ~arity typExpr
109615
+ in
109612
109616
let dotted, attrsBefore =
109613
109617
(* Converting .ml code to .res requires processing uncurried attributes *)
109614
109618
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrsBefore in
@@ -109713,12 +109717,16 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
109713
109717
| Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), "arity0")}, [tArg]) ->
109714
109718
let unitConstr = Location.mkloc (Longident.Lident "unit") tArg.ptyp_loc in
109715
109719
let tUnit = Ast_helper.Typ.constr unitConstr [] in
109716
- printArrow ~uncurried:true
109720
+ printArrow ~uncurried:true ~arity:1
109717
109721
{tArg with ptyp_desc = Ptyp_arrow (Nolabel, tUnit, tArg)}
109718
109722
| Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), arity)}, [tArg])
109719
109723
when String.length arity >= 5
109720
109724
&& (String.sub [@doesNotRaise]) arity 0 5 = "arity" ->
109721
- printArrow ~uncurried:true tArg
109725
+ let arity =
109726
+ int_of_string
109727
+ ((String.sub [@doesNotRaise]) arity 5 (String.length arity - 5))
109728
+ in
109729
+ printArrow ~uncurried:true ~arity tArg
109722
109730
| Ptyp_constr (longidentLoc, [{ptyp_desc = Ptyp_object (fields, openFlag)}])
109723
109731
->
109724
109732
(* for foo<{"a": b}>, when the object is long and needs a line break, we
0 commit comments