From 77aaf8f19bb7c5afa5267b5e431aea2204d8102a Mon Sep 17 00:00:00 2001 From: Onyeka Obi Date: Tue, 21 Jul 2026 21:22:53 -0700 Subject: [PATCH 1/4] Fix functor module type result-signature brace formatting (#7949) --- CHANGELOG.md | 2 ++ compiler/syntax/src/res_printer.ml | 10 +++++++++- .../printer/modExpr/expected/structure.res.txt | 3 +-- .../printer/modType/expected/functor.res.txt | 3 +-- .../modType/expected/functorInterface.resi.txt | 17 +++++++++++++++++ .../data/printer/modType/functorInterface.resi | 17 +++++++++++++++++ 6 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 tests/syntax_tests/data/printer/modType/expected/functorInterface.resi.txt create mode 100644 tests/syntax_tests/data/printer/modType/functorInterface.resi diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c6f8242005..7e5384a0fd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ #### :bug: Bug fix +- 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/PLACEHOLDER_PR + #### :memo: Documentation #### :nail_care: Polish diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index dd15d0bb630..a56837fb1b0 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -931,11 +931,19 @@ and print_mod_type ~state mod_type cmt_tbl = if Parens.mod_type_functor_return return_type then add_parens doc else doc in + (* When the functor result is a signature, keep its opening brace on the + same line as `=>` instead of breaking onto a new line, mirroring how + module-expression functors are printed (see print_mod_functor). *) + let arrow_sep = + match return_type.pmty_desc with + | Pmty_signature _ -> Doc.space + | _ -> Doc.line + in Doc.group (Doc.concat [ parameters_doc; - Doc.group (Doc.concat [Doc.text " =>"; Doc.line; return_doc]); + Doc.group (Doc.concat [Doc.text " =>"; arrow_sep; return_doc]); ]) | Pmty_typeof mod_expr -> Doc.concat diff --git a/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt b/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt index a958790e769..14e1ecd1f67 100644 --- a/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt +++ b/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt @@ -52,8 +52,7 @@ module M3: { include M' } -module G0: (X: {}) => -{ +module G0: (X: {}) => { module N': { let x: int } diff --git a/tests/syntax_tests/data/printer/modType/expected/functor.res.txt b/tests/syntax_tests/data/printer/modType/expected/functor.res.txt index 311a32c474a..4c15e85c1bb 100644 --- a/tests/syntax_tests/data/printer/modType/expected/functor.res.txt +++ b/tests/syntax_tests/data/printer/modType/expected/functor.res.txt @@ -13,7 +13,6 @@ module type Functor = (@attr1 SetLike, @attr2 BtreeLike) => @attr3 NeoTree module type Functor = (SetLike => Set) with type t = A.t module type Functor = SetLike => (Set with type t = A.t) -module type B = () => -{ +module type B = () => { } diff --git a/tests/syntax_tests/data/printer/modType/expected/functorInterface.resi.txt b/tests/syntax_tests/data/printer/modType/expected/functorInterface.resi.txt new file mode 100644 index 00000000000..eeff586b203 --- /dev/null +++ b/tests/syntax_tests/data/printer/modType/expected/functorInterface.resi.txt @@ -0,0 +1,17 @@ +module Make: Pattern => { + let fmt: event => string +} + +module Curried: (A, B) => { + let x: int +} + +module Nested: (A, B) => { + let y: int +} + +module Empty: () => {} + +module ResultIdent: A => B + +module ResultWith: A => (B with type t = int) diff --git a/tests/syntax_tests/data/printer/modType/functorInterface.resi b/tests/syntax_tests/data/printer/modType/functorInterface.resi new file mode 100644 index 00000000000..afaff130183 --- /dev/null +++ b/tests/syntax_tests/data/printer/modType/functorInterface.resi @@ -0,0 +1,17 @@ +module Make: Pattern => { + let fmt: event => string +} + +module Curried: (A, B) => { + let x: int +} + +module Nested: A => B => { + let y: int +} + +module Empty: () => {} + +module ResultIdent: A => B + +module ResultWith: A => (B with type t = int) From 68c814b11d0506a8f0520fe407fc76688caba634 Mon Sep 17 00:00:00 2001 From: Onyeka Obi Date: Wed, 22 Jul 2026 18:57:10 -0700 Subject: [PATCH 2/4] Replace PLACEHOLDER_PR link in CHANGELOG with #8519 Signed-off-by: Onyeka Obi --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e5384a0fd6..f8422ef6e92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ #### :bug: Bug fix -- 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/PLACEHOLDER_PR +- 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 #### :memo: Documentation From 4a48349a78dc351c7122132a1d95be0c63246c59 Mon Sep 17 00:00:00 2001 From: Onyeka Obi Date: Sun, 26 Jul 2026 18:15:43 -0700 Subject: [PATCH 3/4] Add long-name functor module type printer tests Signed-off-by: Onyeka Obi --- .../modType/expected/functorInterface.resi.txt | 11 +++++++++++ .../data/printer/modType/functorInterface.resi | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/tests/syntax_tests/data/printer/modType/expected/functorInterface.resi.txt b/tests/syntax_tests/data/printer/modType/expected/functorInterface.resi.txt index eeff586b203..8dcc62c8735 100644 --- a/tests/syntax_tests/data/printer/modType/expected/functorInterface.resi.txt +++ b/tests/syntax_tests/data/printer/modType/expected/functorInterface.resi.txt @@ -15,3 +15,14 @@ module Empty: () => {} module ResultIdent: A => B module ResultWith: A => (B with type t = int) + +module ThisIsAVeryLongFunctorModuleTypeNameThatExceedsTheEightyCharacterLimit: Pattern => { + let fmt: event => string +} + +module SecondVeryLongFunctorModuleTypeNameWithMultipleShortParameters: (A, B) => { + let x: int +} + +module YetAnotherVeryLongFunctorModuleTypeNameHere: SomeVeryLongParameterModuleTypeName => +SomeVeryLongResultingModuleTypeName diff --git a/tests/syntax_tests/data/printer/modType/functorInterface.resi b/tests/syntax_tests/data/printer/modType/functorInterface.resi index afaff130183..07a8aa5a108 100644 --- a/tests/syntax_tests/data/printer/modType/functorInterface.resi +++ b/tests/syntax_tests/data/printer/modType/functorInterface.resi @@ -15,3 +15,13 @@ module Empty: () => {} module ResultIdent: A => B module ResultWith: A => (B with type t = int) + +module ThisIsAVeryLongFunctorModuleTypeNameThatExceedsTheEightyCharacterLimit: Pattern => { + let fmt: event => string +} + +module SecondVeryLongFunctorModuleTypeNameWithMultipleShortParameters: (A, B) => { + let x: int +} + +module YetAnotherVeryLongFunctorModuleTypeNameHere: SomeVeryLongParameterModuleTypeName => SomeVeryLongResultingModuleTypeName From 90d904203fd29d9ad46400589255dc293d78548a Mon Sep 17 00:00:00 2001 From: Onyeka Obi Date: Sun, 26 Jul 2026 23:24:51 -0700 Subject: [PATCH 4/4] Add long-name functor module type printer tests for .res syntax Signed-off-by: Onyeka Obi --- .../data/printer/modType/expected/functor.res.txt | 11 +++++++++++ tests/syntax_tests/data/printer/modType/functor.res | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/syntax_tests/data/printer/modType/expected/functor.res.txt b/tests/syntax_tests/data/printer/modType/expected/functor.res.txt index 4c15e85c1bb..2af4bf0c652 100644 --- a/tests/syntax_tests/data/printer/modType/expected/functor.res.txt +++ b/tests/syntax_tests/data/printer/modType/expected/functor.res.txt @@ -16,3 +16,14 @@ module type Functor = SetLike => (Set with type t = A.t) module type B = () => { } + +module type ThisIsAVeryLongFunctorModuleTypeNameThatExceedsTheEightyCharacterLimit = Pattern => { + let fmt: event => string +} + +module type SecondVeryLongFunctorModuleTypeNameWithMultipleShortParameters = (A, B) => { + let x: int +} + +module type YetAnotherVeryLongFunctorModuleTypeNameHere = SomeVeryLongParameterModuleTypeName => +SomeVeryLongResultingModuleTypeName diff --git a/tests/syntax_tests/data/printer/modType/functor.res b/tests/syntax_tests/data/printer/modType/functor.res index 9149ed582c6..cea142cee36 100644 --- a/tests/syntax_tests/data/printer/modType/functor.res +++ b/tests/syntax_tests/data/printer/modType/functor.res @@ -16,4 +16,14 @@ module type Functor = SetLike => (Set with type t = A.t) module type B = () => { -} \ No newline at end of file +} + +module type ThisIsAVeryLongFunctorModuleTypeNameThatExceedsTheEightyCharacterLimit = Pattern => { + let fmt: event => string +} + +module type SecondVeryLongFunctorModuleTypeNameWithMultipleShortParameters = (A, B) => { + let x: int +} + +module type YetAnotherVeryLongFunctorModuleTypeNameHere = SomeVeryLongParameterModuleTypeName => SomeVeryLongResultingModuleTypeName \ No newline at end of file