@@ -553,12 +553,12 @@ end
553
553
let is_inline_record_definition attrs =
554
554
attrs
555
555
|> List. exists (fun (({txt} , _ ) : Parsetree. attribute ) ->
556
- txt = " inlineRecordDefinition" )
556
+ txt = " res. inlineRecordDefinition" )
557
557
558
558
let is_inline_record_reference attrs =
559
559
attrs
560
560
|> List. exists (fun (({txt} , _ ) : Parsetree. attribute ) ->
561
- txt = " inlineRecordReference" )
561
+ txt = " res. inlineRecordReference" )
562
562
563
563
let rec print_structure ~state (s : Parsetree.structure ) t =
564
564
match s with
@@ -587,9 +587,7 @@ and print_structure_item ~state (si : Parsetree.structure_item) cmt_tbl =
587
587
let inline_record_definitions, regular_declarations =
588
588
type_declarations
589
589
|> List. partition (fun (td : Parsetree.type_declaration ) ->
590
- td.ptype_attributes
591
- |> List. exists (fun (({txt} , _ ) : Parsetree. attribute ) ->
592
- txt = " inlineRecordDefinition" ))
590
+ is_inline_record_definition td.ptype_attributes)
593
591
in
594
592
print_type_declarations ~inline_record_definitions ~state
595
593
~rec_flag:
@@ -1616,28 +1614,11 @@ and print_label_declaration ?inline_record_definitions ~state
1616
1614
name;
1617
1615
optional;
1618
1616
(if is_dot then Doc. nil else Doc. text " : " );
1619
- (match
1620
- ( inline_record_definitions,
1621
- is_inline_record_reference ld.pld_type.ptyp_attributes,
1622
- ld.pld_type )
1623
- with
1624
- | ( Some inline_record_definitions,
1625
- true ,
1626
- {ptyp_desc = Ptyp_constr ({txt = Lident constr_name}, _)} ) -> (
1627
- let record_definition =
1628
- inline_record_definitions
1629
- |> List. find_opt (fun (r : Parsetree.type_declaration ) ->
1630
- r.ptype_name.txt = constr_name)
1631
- in
1632
- match record_definition with
1633
- | Some {ptype_kind = Ptype_record lds } ->
1634
- print_record_declaration ~inline_record_definitions ~state lds
1635
- cmt_tbl
1636
- | _ -> assert false )
1637
- | _ -> print_typ_expr ~state ld.pld_type cmt_tbl);
1617
+ print_typ_expr ?inline_record_definitions ~state ld.pld_type cmt_tbl;
1638
1618
])
1639
1619
1640
- and print_typ_expr ~(state : State.t ) (typ_expr : Parsetree.core_type ) cmt_tbl =
1620
+ and print_typ_expr ?inline_record_definitions ~(state : State.t )
1621
+ (typ_expr : Parsetree.core_type ) cmt_tbl =
1641
1622
let print_arrow ~arity typ_expr =
1642
1623
let max_arity =
1643
1624
match arity with
@@ -1742,6 +1723,22 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
1742
1723
| Ptyp_object (fields , open_flag ) ->
1743
1724
print_object ~state ~inline: false fields open_flag cmt_tbl
1744
1725
| Ptyp_arrow (_ , _ , _ , arity ) -> print_arrow ~arity typ_expr
1726
+ | Ptyp_constr ({txt = Lident inline_record_name}, [] )
1727
+ when is_inline_record_reference typ_expr.ptyp_attributes -> (
1728
+ let inline_record_definitions =
1729
+ match inline_record_definitions with
1730
+ | None -> []
1731
+ | Some v -> v
1732
+ in
1733
+ let record_definition =
1734
+ inline_record_definitions
1735
+ |> List. find_opt (fun (r : Parsetree.type_declaration ) ->
1736
+ r.ptype_name.txt = inline_record_name)
1737
+ in
1738
+ match record_definition with
1739
+ | Some {ptype_kind = Ptype_record lds } ->
1740
+ print_record_declaration ~inline_record_definitions ~state lds cmt_tbl
1741
+ | _ -> assert false )
1745
1742
| Ptyp_constr
1746
1743
(longident_loc, [{ptyp_desc = Ptyp_object (fields, open_flag)}]) ->
1747
1744
(* for foo<{"a": b}>, when the object is long and needs a line break, we
@@ -1782,15 +1779,17 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
1782
1779
~sep: (Doc. concat [Doc. comma; Doc. line])
1783
1780
(List. map
1784
1781
(fun typexpr ->
1785
- print_typ_expr ~state typexpr cmt_tbl)
1782
+ print_typ_expr ?inline_record_definitions ~state
1783
+ typexpr cmt_tbl)
1786
1784
constr_args);
1787
1785
]);
1788
1786
Doc. trailing_comma;
1789
1787
Doc. soft_line;
1790
1788
Doc. greater_than;
1791
1789
]))
1792
1790
| Ptyp_tuple types -> print_tuple_type ~state ~inline: false types cmt_tbl
1793
- | Ptyp_poly ([] , typ ) -> print_typ_expr ~state typ cmt_tbl
1791
+ | Ptyp_poly ([] , typ ) ->
1792
+ print_typ_expr ?inline_record_definitions ~state typ cmt_tbl
1794
1793
| Ptyp_poly (string_locs , typ ) ->
1795
1794
Doc. concat
1796
1795
[
0 commit comments