Skip to content

Commit e4559c8

Browse files
committed
for inline records, calculate force break from the record body itself
1 parent 3362a87 commit e4559c8

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

compiler/syntax/src/res_printer.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,13 +1464,14 @@ and print_type_param ~state (param : Parsetree.core_type * Asttypes.variance)
14641464
in
14651465
Doc.concat [printed_variance; print_typ_expr ~state typ cmt_tbl]
14661466

1467-
and print_record_declaration ?inline_record_definitions ~state
1468-
(lds : Parsetree.label_declaration list) cmt_tbl =
1467+
and print_record_declaration ?check_break_from_loc ?inline_record_definitions
1468+
~state (lds : Parsetree.label_declaration list) cmt_tbl =
14691469
let force_break =
1470-
match (lds, List.rev lds) with
1471-
| first :: _, last :: _ ->
1470+
match (check_break_from_loc, lds, List.rev lds) with
1471+
| Some loc, _, _ -> loc.Location.loc_start.pos_lnum < loc.loc_end.pos_lnum
1472+
| _, first :: _, last :: _ ->
14721473
first.pld_loc.loc_start.pos_lnum < last.pld_loc.loc_end.pos_lnum
1473-
| _ -> false
1474+
| _, _, _ -> false
14741475
in
14751476
Doc.breakable_group ~force_break
14761477
(Doc.concat
@@ -1805,8 +1806,8 @@ and print_typ_expr ?inline_record_definitions ~(state : State.t)
18051806
inline_record_definitions
18061807
|> find_inline_record_definition inline_record_name
18071808
with
1808-
| Some {ptype_kind = Ptype_record lds} ->
1809-
print_record_declaration
1809+
| Some {ptype_kind = Ptype_record lds; ptype_loc} ->
1810+
print_record_declaration ~check_break_from_loc:ptype_loc
18101811
~inline_record_definitions:(inline_record_definitions |> Option.get)
18111812
~state lds cmt_tbl
18121813
| _ -> assert false)

tests/syntax_tests/data/printer/signature/expected/type.resi.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ type color =
88
| Black
99

1010
type options = {
11-
permissions: {all: bool},
11+
permissions: {
12+
all: {
13+
stuff: bool,
14+
},
15+
},
1216
}

tests/syntax_tests/data/printer/signature/type.resi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ type color =
99

1010
type options = {
1111
permissions: {
12-
all: bool
12+
all: {
13+
stuff: bool
14+
}
1315
}
1416
}

0 commit comments

Comments
 (0)