File tree 3 files changed +12
-12
lines changed
3 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ let print_ct ct =
25
25
| {ptyp_desc = Ptyp_variant _ } -> print_endline " Ptyp_variant"
26
26
| _ -> print_endline " Something else"
27
27
28
- let arrow_type ?(arity = max_int) ct =
28
+ let arrow_type ?(arity = max_int) ?( attrs = [] ) ct =
29
29
let has_as_attr attrs =
30
30
Ext_list. exists attrs (fun (x , _ ) -> x.Asttypes. txt = " as" )
31
31
in
@@ -70,10 +70,11 @@ let arrow_type ?(arity = max_int) ct =
70
70
| typ -> (attrs_before, List. rev acc, typ)
71
71
in
72
72
match ct with
73
- | {ptyp_desc = Ptyp_arrow (Nolabel , _typ1, _typ2); ptyp_attributes = attrs} as
74
- typ ->
73
+ | {ptyp_desc = Ptyp_arrow (Nolabel , _typ1, _typ2); ptyp_attributes = attrs1}
74
+ as typ ->
75
+ let attrs = List. concat [attrs; attrs1] in
75
76
process attrs [] {typ with ptyp_attributes = [] } arity
76
- | typ -> process [] [] typ arity
77
+ | typ -> process attrs [] typ arity
77
78
78
79
let functor_type modtype =
79
80
let rec process acc modtype =
Original file line number Diff line number Diff line change 3
3
* we restructure the tree into (a, b, c) and its returnType d *)
4
4
val arrow_type :
5
5
?arity : int ->
6
+ ?attrs : Parsetree .attributes ->
6
7
Parsetree .core_type ->
7
8
Parsetree .attributes
8
9
* (Parsetree .attributes * Asttypes .arg_label * Parsetree .core_type ) list
Original file line number Diff line number Diff line change @@ -1591,17 +1591,13 @@ and print_label_declaration ~state (ld : Parsetree.label_declaration) cmt_tbl =
1591
1591
])
1592
1592
1593
1593
and print_typ_expr ~(state : State.t ) (typ_expr : Parsetree.core_type ) cmt_tbl =
1594
- let parent_has_attrs =
1594
+ let parent_attrs =
1595
1595
let attrs = ParsetreeViewer. filter_parsing_attrs typ_expr.ptyp_attributes in
1596
- if Ast_uncurried. core_type_is_uncurried_fun typ_expr && not (attrs = [] )
1597
- then
1598
- let arity, _ = Ast_uncurried. core_type_extract_uncurried_fun typ_expr in
1599
- arity > 0
1600
- else false
1596
+ if Ast_uncurried. core_type_is_uncurried_fun typ_expr then attrs else []
1601
1597
in
1602
1598
let print_arrow ?(arity = max_int) typ_expr =
1603
1599
let attrs_before, args, return_type =
1604
- ParsetreeViewer. arrow_type ~arity typ_expr
1600
+ ParsetreeViewer. arrow_type ~arity ~attrs: parent_attrs typ_expr
1605
1601
in
1606
1602
let return_type_needs_parens =
1607
1603
match return_type.ptyp_desc with
@@ -1634,7 +1630,7 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
1634
1630
[
1635
1631
Doc. group attrs;
1636
1632
Doc. group
1637
- (if has_attrs_before || parent_has_attrs then
1633
+ (if has_attrs_before then
1638
1634
Doc. concat
1639
1635
[
1640
1636
Doc. lparen;
@@ -1849,6 +1845,8 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
1849
1845
in
1850
1846
let should_print_its_own_attributes =
1851
1847
match typ_expr.ptyp_desc with
1848
+ | Ptyp_constr _ when Ast_uncurried. core_type_is_uncurried_fun typ_expr ->
1849
+ true
1852
1850
| Ptyp_arrow _ (* es6 arrow types print their own attributes *) -> true
1853
1851
| _ -> false
1854
1852
in
You can’t perform that action at this time.
0 commit comments