diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dcfb0ee52a..93d82be523d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ - 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 - 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 - 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 +- 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 - 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 - Preserve parentheses around multiplication, division, and modulo expressions used as exponents. https://github.com/rescript-lang/rescript/pull/8550 - 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 diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index 7893e4f3209..86bc722bf74 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -1862,7 +1862,7 @@ and print_constructor_arguments ?(is_dot_dot_dot = false) ~state ~indent Doc.rparen; ] in - if indent then Doc.indent args else args + Doc.group (if indent then Doc.indent args else args) and print_label_declaration ?inline_record_definitions ~state (ld : Parsetree.label_declaration) cmt_tbl = diff --git a/tests/syntax_tests/data/printer/signature/exception.resi b/tests/syntax_tests/data/printer/signature/exception.resi index 5f5382744c4..a4acd213351 100644 --- a/tests/syntax_tests/data/printer/signature/exception.resi +++ b/tests/syntax_tests/data/printer/signature/exception.resi @@ -6,3 +6,8 @@ exception ExitEarly exception Exit = Terminate exception Exit = Lib.Terminate exception Exit = Ns.Lib.Terminate + +/** doc comment */ +exception ExitEarly({x: int}) +/** doc comment */ +exception ExitEarly({x: int, y: string}) diff --git a/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt b/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt index 98166b15694..a2d580c8a34 100644 --- a/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt +++ b/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt @@ -5,3 +5,8 @@ exception Exit exception Exit = Terminate exception Exit = Lib.Terminate exception Exit = Ns.Lib.Terminate + +/** doc comment */ +exception ExitEarly({x: int}) +/** doc comment */ +exception ExitEarly({x: int, y: string}) diff --git a/tests/syntax_tests/data/printer/structure/exception.res b/tests/syntax_tests/data/printer/structure/exception.res index 528624e9c6f..f70fa61c0ec 100644 --- a/tests/syntax_tests/data/printer/structure/exception.res +++ b/tests/syntax_tests/data/printer/structure/exception.res @@ -34,3 +34,10 @@ exception Exit = Terminate @onConstructor exception Exit = Lib.Terminate exception GadtExit(int): exit + +/** doc comment */ +exception ExitEarly({x: int}) +/** doc comment */ +exception ExitEarly({x: int, y: string}) +/** doc comment */ +exception ExitEarlyWithManyFields({firstFieldName: int, secondFieldName: string, thirdFieldName: bool, fourthFieldName: float}) diff --git a/tests/syntax_tests/data/printer/structure/expected/exception.res.txt b/tests/syntax_tests/data/printer/structure/expected/exception.res.txt index 294d17e14f8..03f26bf5c0e 100644 --- a/tests/syntax_tests/data/printer/structure/expected/exception.res.txt +++ b/tests/syntax_tests/data/printer/structure/expected/exception.res.txt @@ -30,3 +30,15 @@ exception Exit = Ns.Lib.Terminate @onConstructor exception Exit = Terminate @onConstructor exception Exit = Lib.Terminate exception GadtExit(int): exit + +/** doc comment */ +exception ExitEarly({x: int}) +/** doc comment */ +exception ExitEarly({x: int, y: string}) +/** doc comment */ +exception ExitEarlyWithManyFields({ + firstFieldName: int, + secondFieldName: string, + thirdFieldName: bool, + fourthFieldName: float, +}) diff --git a/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt b/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt index 4fef7768185..e2909556320 100644 --- a/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt +++ b/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt @@ -89,3 +89,7 @@ module type Tid = { | Uid: Tid.u | Uid2: Tid.u } + +type t += + | /** doc comment */ + Ext({name: string, msg: string}) diff --git a/tests/syntax_tests/data/printer/structure/typeExtension.res b/tests/syntax_tests/data/printer/structure/typeExtension.res index 09bd8b4fce5..3b55add6ecf 100644 --- a/tests/syntax_tests/data/printer/structure/typeExtension.res +++ b/tests/syntax_tests/data/printer/structure/typeExtension.res @@ -90,3 +90,5 @@ module type Tid = { | Uid: Tid.u | Uid2: Tid.u } + +type t += /** doc comment */ Ext({name: string, msg: string})