Skip to content

Commit b4daa71

Browse files
committed
Fix formatter forcing doc-commented inline-record exceptions onto multiple lines (#7947)
Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
1 parent bc382a4 commit b4daa71

8 files changed

Lines changed: 37 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
- Fix externals whose result type is an alias of `unit` so they use the same unit-return behavior as externals declared to return `unit`. https://github.com/rescript-lang/rescript/pull/8581
4545
- Fix dynamic imports of external bindings that require FFI argument or result conversions, including `@variadic`, `@unwrap`, polymorphic variant encodings, `@as` phantom arguments, optional labeled arguments, and `@return` wrappers. The imported value now applies the same conversions as a direct external call. https://github.com/rescript-lang/rescript/pull/8582
4646
- Fix formatter breaking the opening brace of a functor module type's result signature onto a new line (e.g. `module Make: Pattern => {`). https://github.com/rescript-lang/rescript/pull/8519
47+
- Fix formatter breaking an inline-record `exception` constructor onto several lines when the declaration carries a doc comment (`/** doc */ exception Foo({name: string, msg: string})`). The record argument now forms its own group, as the tuple argument already did, so the line break after the doc comment no longer propagates into the record. Inline-record type extension constructors (`type t += Ext({...})`) get the same treatment. https://github.com/rescript-lang/rescript/pull/8622
4748
- Fix argument evaluation order when a function call is inlined: the beta reducer stacked argument bindings in reverse parameter order, so the last argument was evaluated first when arguments could not be substituted directly. https://github.com/rescript-lang/rescript/pull/8572
4849
- Preserve parentheses around multiplication, division, and modulo expressions used as exponents. https://github.com/rescript-lang/rescript/pull/8550
4950
- Make a function's locally abstract types (`(type t, x) => ...`) part of the function AST node instead of a chain of wrapper nodes. Fixes the formatter dropping the association of attributes with their `type` group (`(@attr type t, x, @attr2 type s, y)` used to print as `@attr @attr2` on the function) and comments written next to a type parameter migrating onto the following value parameter. https://github.com/rescript-lang/rescript/pull/8574

compiler/syntax/src/res_printer.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1862,7 +1862,7 @@ and print_constructor_arguments ?(is_dot_dot_dot = false) ~state ~indent
18621862
Doc.rparen;
18631863
]
18641864
in
1865-
if indent then Doc.indent args else args
1865+
Doc.group (if indent then Doc.indent args else args)
18661866

18671867
and print_label_declaration ?inline_record_definitions ~state
18681868
(ld : Parsetree.label_declaration) cmt_tbl =

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ exception ExitEarly
66
exception Exit = Terminate
77
exception Exit = Lib.Terminate
88
exception Exit = Ns.Lib.Terminate
9+
10+
/** doc comment */
11+
exception ExitEarly({x: int})
12+
/** doc comment */
13+
exception ExitEarly({x: int, y: string})

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ exception Exit
55
exception Exit = Terminate
66
exception Exit = Lib.Terminate
77
exception Exit = Ns.Lib.Terminate
8+
9+
/** doc comment */
10+
exception ExitEarly({x: int})
11+
/** doc comment */
12+
exception ExitEarly({x: int, y: string})

tests/syntax_tests/data/printer/structure/exception.res

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ exception Exit = Terminate
3434
@onConstructor
3535
exception Exit = Lib.Terminate
3636
exception GadtExit(int): exit<int>
37+
38+
/** doc comment */
39+
exception ExitEarly({x: int})
40+
/** doc comment */
41+
exception ExitEarly({x: int, y: string})
42+
/** doc comment */
43+
exception ExitEarlyWithManyFields({firstFieldName: int, secondFieldName: string, thirdFieldName: bool, fourthFieldName: float})

tests/syntax_tests/data/printer/structure/expected/exception.res.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,15 @@ exception Exit = Ns.Lib.Terminate
3030
@onConstructor exception Exit = Terminate
3131
@onConstructor exception Exit = Lib.Terminate
3232
exception GadtExit(int): exit<int>
33+
34+
/** doc comment */
35+
exception ExitEarly({x: int})
36+
/** doc comment */
37+
exception ExitEarly({x: int, y: string})
38+
/** doc comment */
39+
exception ExitEarlyWithManyFields({
40+
firstFieldName: int,
41+
secondFieldName: string,
42+
thirdFieldName: bool,
43+
fourthFieldName: float,
44+
})

tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,7 @@ module type Tid = {
8989
| Uid: Tid.u<t>
9090
| Uid2: Tid.u<t>
9191
}
92+
93+
type t +=
94+
| /** doc comment */
95+
Ext({name: string, msg: string})

tests/syntax_tests/data/printer/structure/typeExtension.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ module type Tid = {
9090
| Uid: Tid.u<t>
9191
| Uid2: Tid.u<t>
9292
}
93+
94+
type t += /** doc comment */ Ext({name: string, msg: string})

0 commit comments

Comments
 (0)