@@ -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:
@@ -1614,28 +1612,11 @@ and print_label_declaration ?inline_record_definitions ~state
1614
1612
name;
1615
1613
optional;
1616
1614
(if is_dot then Doc. nil else Doc. text " : " );
1617
- (match
1618
- ( inline_record_definitions,
1619
- is_inline_record_reference ld.pld_type.ptyp_attributes,
1620
- ld.pld_type )
1621
- with
1622
- | ( Some inline_record_definitions,
1623
- true ,
1624
- {ptyp_desc = Ptyp_constr ({txt = Lident constr_name}, _)} ) -> (
1625
- let record_definition =
1626
- inline_record_definitions
1627
- |> List. find_opt (fun (r : Parsetree.type_declaration ) ->
1628
- r.ptype_name.txt = constr_name)
1629
- in
1630
- match record_definition with
1631
- | Some {ptype_kind = Ptype_record lds } ->
1632
- print_record_declaration ~inline_record_definitions ~state lds
1633
- cmt_tbl
1634
- | _ -> assert false )
1635
- | _ -> print_typ_expr ~state ld.pld_type cmt_tbl);
1615
+ print_typ_expr ?inline_record_definitions ~state ld.pld_type cmt_tbl;
1636
1616
])
1637
1617
1638
- and print_typ_expr ~(state : State.t ) (typ_expr : Parsetree.core_type ) cmt_tbl =
1618
+ and print_typ_expr ?inline_record_definitions ~(state : State.t )
1619
+ (typ_expr : Parsetree.core_type ) cmt_tbl =
1639
1620
let print_arrow ~arity typ_expr =
1640
1621
let max_arity =
1641
1622
match arity with
@@ -1740,6 +1721,22 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
1740
1721
| Ptyp_object (fields , open_flag ) ->
1741
1722
print_object ~state ~inline: false fields open_flag cmt_tbl
1742
1723
| Ptyp_arrow {arity} -> print_arrow ~arity typ_expr
1724
+ | Ptyp_constr ({txt = Lident inline_record_name}, [] )
1725
+ when is_inline_record_reference typ_expr.ptyp_attributes -> (
1726
+ let inline_record_definitions =
1727
+ match inline_record_definitions with
1728
+ | None -> []
1729
+ | Some v -> v
1730
+ in
1731
+ let record_definition =
1732
+ inline_record_definitions
1733
+ |> List. find_opt (fun (r : Parsetree.type_declaration ) ->
1734
+ r.ptype_name.txt = inline_record_name)
1735
+ in
1736
+ match record_definition with
1737
+ | Some {ptype_kind = Ptype_record lds } ->
1738
+ print_record_declaration ~inline_record_definitions ~state lds cmt_tbl
1739
+ | _ -> assert false )
1743
1740
| Ptyp_constr
1744
1741
(longident_loc, [{ptyp_desc = Ptyp_object (fields, open_flag)}]) ->
1745
1742
(* for foo<{"a": b}>, when the object is long and needs a line break, we
@@ -1780,15 +1777,17 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
1780
1777
~sep: (Doc. concat [Doc. comma; Doc. line])
1781
1778
(List. map
1782
1779
(fun typexpr ->
1783
- print_typ_expr ~state typexpr cmt_tbl)
1780
+ print_typ_expr ?inline_record_definitions ~state
1781
+ typexpr cmt_tbl)
1784
1782
constr_args);
1785
1783
]);
1786
1784
Doc. trailing_comma;
1787
1785
Doc. soft_line;
1788
1786
Doc. greater_than;
1789
1787
]))
1790
1788
| Ptyp_tuple types -> print_tuple_type ~state ~inline: false types cmt_tbl
1791
- | Ptyp_poly ([] , typ ) -> print_typ_expr ~state typ cmt_tbl
1789
+ | Ptyp_poly ([] , typ ) ->
1790
+ print_typ_expr ?inline_record_definitions ~state typ cmt_tbl
1792
1791
| Ptyp_poly (string_locs , typ ) ->
1793
1792
Doc. concat
1794
1793
[
0 commit comments