@@ -553,12 +553,12 @@ end
553553let is_inline_record_definition attrs =
554554 attrs
555555 |> List. exists (fun (({txt} , _ ) : Parsetree. attribute ) ->
556- txt = " inlineRecordDefinition" )
556+ txt = " res. inlineRecordDefinition" )
557557
558558let is_inline_record_reference attrs =
559559 attrs
560560 |> List. exists (fun (({txt} , _ ) : Parsetree. attribute ) ->
561- txt = " inlineRecordReference" )
561+ txt = " res. inlineRecordReference" )
562562
563563let rec print_structure ~state (s : Parsetree.structure ) t =
564564 match s with
@@ -587,9 +587,7 @@ and print_structure_item ~state (si : Parsetree.structure_item) cmt_tbl =
587587 let inline_record_definitions, regular_declarations =
588588 type_declarations
589589 |> 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)
593591 in
594592 print_type_declarations ~inline_record_definitions ~state
595593 ~rec_flag:
@@ -1616,28 +1614,11 @@ and print_label_declaration ?inline_record_definitions ~state
16161614 name;
16171615 optional;
16181616 (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;
16381618 ])
16391619
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 =
16411622 let print_arrow ~arity typ_expr =
16421623 let max_arity =
16431624 match arity with
@@ -1742,6 +1723,22 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
17421723 | Ptyp_object (fields , open_flag ) ->
17431724 print_object ~state ~inline: false fields open_flag cmt_tbl
17441725 | 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 )
17451742 | Ptyp_constr
17461743 (longident_loc, [{ptyp_desc = Ptyp_object (fields, open_flag)}]) ->
17471744 (* 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 =
17821779 ~sep: (Doc. concat [Doc. comma; Doc. line])
17831780 (List. map
17841781 (fun typexpr ->
1785- print_typ_expr ~state typexpr cmt_tbl)
1782+ print_typ_expr ?inline_record_definitions ~state
1783+ typexpr cmt_tbl)
17861784 constr_args);
17871785 ]);
17881786 Doc. trailing_comma;
17891787 Doc. soft_line;
17901788 Doc. greater_than;
17911789 ]))
17921790 | 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
17941793 | Ptyp_poly (string_locs , typ ) ->
17951794 Doc. concat
17961795 [
0 commit comments