@@ -1665,14 +1665,14 @@ and print_type_param ~state (param : Parsetree.core_type * Asttypes.variance)
16651665 in
16661666 Doc. concat [printed_variance; print_typ_expr ~state typ cmt_tbl]
16671667
1668+ and get_field_start_line (ld : Parsetree.label_declaration ) =
1669+ (* For spread fields (...), use the type location instead of pld_loc
1670+ because pld_loc may incorrectly include preceding whitespace *)
1671+ if ld.pld_name.txt = " ..." then ld.pld_type.ptyp_loc.loc_start.pos_lnum
1672+ else ld.pld_loc.loc_start.pos_lnum
1673+
16681674and print_record_declaration ?check_break_from_loc ?inline_record_definitions
16691675 ?record_loc ~state (lds : Parsetree.label_declaration list ) cmt_tbl =
1670- let get_field_start_line (ld : Parsetree.label_declaration ) =
1671- (* For spread fields (...), use the type location instead of pld_loc
1672- because pld_loc may incorrectly include preceding whitespace *)
1673- if ld.pld_name.txt = " ..." then ld.pld_type.ptyp_loc.loc_start.pos_lnum
1674- else ld.pld_loc.loc_start.pos_lnum
1675- in
16761676 let force_break =
16771677 match (check_break_from_loc, record_loc, lds) with
16781678 | Some loc , _ , _ -> loc.Location. loc_start.pos_lnum < loc.loc_end.pos_lnum
@@ -1855,8 +1855,8 @@ and print_constructor_declaration2 ~state i
18551855 print_comments doc cmt_tbl cd.pcd_name.loc
18561856 in
18571857 let constr_args =
1858- print_constructor_arguments ~is_dot_dot_dot ~state ~indent: true cd.pcd_args
1859- cmt_tbl
1858+ print_constructor_arguments ~is_dot_dot_dot ~name_loc: cd.pcd_name.loc ~state
1859+ ~indent: true cd.pcd_args cmt_tbl
18601860 in
18611861 let gadt =
18621862 match cd.pcd_res with
@@ -1879,8 +1879,8 @@ and print_constructor_declaration2 ~state i
18791879 ]);
18801880 ]
18811881
1882- and print_constructor_arguments ?(is_dot_dot_dot = false ) ~state ~ indent
1883- (cd_args : Parsetree.constructor_arguments ) cmt_tbl =
1882+ and print_constructor_arguments ?(is_dot_dot_dot = false ) ~name_loc ~ state
1883+ ~ indent (cd_args : Parsetree.constructor_arguments ) cmt_tbl =
18841884 match cd_args with
18851885 | Pcstr_tuple [] -> Doc. nil
18861886 | Pcstr_tuple types ->
@@ -1929,7 +1929,15 @@ and print_constructor_arguments ?(is_dot_dot_dot = false) ~state ~indent
19291929 Doc. rparen;
19301930 ]
19311931 in
1932- Doc. group (if indent then Doc. indent args else args)
1932+ (* Like a record type declaration, keep the inline record multiline when
1933+ the first field starts on a later line than the constructor name. *)
1934+ let force_break =
1935+ match lds with
1936+ | first :: _ ->
1937+ name_loc.Location. loc_end.pos_lnum < get_field_start_line first
1938+ | [] -> false
1939+ in
1940+ Doc. breakable_group ~force_break (if indent then Doc. indent args else args)
19331941
19341942and print_label_declaration ?inline_record_definitions ~state
19351943 (ld : Parsetree.label_declaration ) cmt_tbl =
@@ -6449,7 +6457,9 @@ and print_exception_def ~state (constr : Parsetree.extension_constructor)
64496457 in
64506458 Doc. concat
64516459 [
6452- print_constructor_arguments ~state ~indent: false args cmt_tbl; gadt_doc;
6460+ print_constructor_arguments ~name_loc: constr.pext_name.loc ~state
6461+ ~indent: false args cmt_tbl;
6462+ gadt_doc;
64536463 ]
64546464 in
64556465 let name =
@@ -6489,7 +6499,9 @@ and print_extension_constructor ~state
64896499 in
64906500 Doc. concat
64916501 [
6492- print_constructor_arguments ~state ~indent: false args cmt_tbl; gadt_doc;
6502+ print_constructor_arguments ~name_loc: constr.pext_name.loc ~state
6503+ ~indent: false args cmt_tbl;
6504+ gadt_doc;
64936505 ]
64946506 in
64956507 let name =
0 commit comments