Skip to content

Commit a22a0a9

Browse files
committed
Change how force_break is handled in type declaration printing
1 parent d50570d commit a22a0a9

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

compiler/syntax/src/res_printer.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ and print_type_declaration ~state ~name ~equal_sign ~rec_flag i
12821282
manifest;
12831283
Doc.concat [Doc.space; Doc.text equal_sign; Doc.space];
12841284
print_private_flag td.ptype_private;
1285-
print_record_declaration ~state lds cmt_tbl;
1285+
print_record_declaration ~record_loc:td.ptype_loc ~state lds cmt_tbl;
12861286
]
12871287
| Ptype_variant cds ->
12881288
let manifest =
@@ -1370,8 +1370,8 @@ and print_type_declaration2 ?inline_record_definitions ~state ~rec_flag
13701370
manifest;
13711371
Doc.concat [Doc.space; Doc.text equal_sign; Doc.space];
13721372
print_private_flag td.ptype_private;
1373-
print_record_declaration ?inline_record_definitions ~state lds
1374-
cmt_tbl;
1373+
print_record_declaration ?inline_record_definitions
1374+
~record_loc:td.ptype_loc ~state lds cmt_tbl;
13751375
]
13761376
| Ptype_variant cds ->
13771377
let manifest =
@@ -1465,11 +1465,15 @@ and print_type_param ~state (param : Parsetree.core_type * Asttypes.variance)
14651465
Doc.concat [printed_variance; print_typ_expr ~state typ cmt_tbl]
14661466

14671467
and print_record_declaration ?check_break_from_loc ?inline_record_definitions
1468-
~state (lds : Parsetree.label_declaration list) cmt_tbl =
1468+
?record_loc ~state (lds : Parsetree.label_declaration list) cmt_tbl =
14691469
let force_break =
1470-
match (check_break_from_loc, lds, List.rev lds) with
1470+
match (check_break_from_loc, record_loc, lds) with
14711471
| Some loc, _, _ -> loc.Location.loc_start.pos_lnum < loc.loc_end.pos_lnum
1472-
| _, first :: _, last :: _ ->
1472+
| None, Some loc, first :: _ ->
1473+
(* Check if first field is on a different line than the opening brace *)
1474+
loc.loc_start.pos_lnum < first.Parsetree.pld_loc.loc_start.pos_lnum
1475+
| None, None, first :: _ ->
1476+
let last = List.hd (List.rev lds) in
14731477
first.pld_loc.loc_start.pos_lnum < last.pld_loc.loc_end.pos_lnum
14741478
| _, _, _ -> false
14751479
in

0 commit comments

Comments
 (0)