@@ -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:
@@ -1614,28 +1612,11 @@ and print_label_declaration ?inline_record_definitions ~state
16141612 name;
16151613 optional;
16161614 (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;
16361616 ])
16371617
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 =
16391620 let print_arrow ~arity typ_expr =
16401621 let max_arity =
16411622 match arity with
@@ -1740,6 +1721,22 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
17401721 | Ptyp_object (fields , open_flag ) ->
17411722 print_object ~state ~inline: false fields open_flag cmt_tbl
17421723 | 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 )
17431740 | Ptyp_constr
17441741 (longident_loc, [{ptyp_desc = Ptyp_object (fields, open_flag)}]) ->
17451742 (* 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 =
17801777 ~sep: (Doc. concat [Doc. comma; Doc. line])
17811778 (List. map
17821779 (fun typexpr ->
1783- print_typ_expr ~state typexpr cmt_tbl)
1780+ print_typ_expr ?inline_record_definitions ~state
1781+ typexpr cmt_tbl)
17841782 constr_args);
17851783 ]);
17861784 Doc. trailing_comma;
17871785 Doc. soft_line;
17881786 Doc. greater_than;
17891787 ]))
17901788 | 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
17921791 | Ptyp_poly (string_locs , typ ) ->
17931792 Doc. concat
17941793 [
0 commit comments