Skip to content

Commit 7917ea3

Browse files
authored
Fix formatter removed parens from functor type (#7735)
* Print () instead of Doc.nil * Handle functor with no arg * Update test * Update CHANGELOG
1 parent f04e3b3 commit 7917ea3

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#### :bug: Bug fix
2424

2525
- Fix error message that falsely suggested using coercion when it wouldn't work. https://github.com/rescript-lang/rescript/pull/7721
26+
- Fix formatter removes () from functor type. https://github.com/rescript-lang/rescript/pull/7735
2627

2728
# 12.0.0-beta.3
2829

compiler/syntax/src/res_printer.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,10 @@ and print_mod_type ~state mod_type cmt_tbl =
807807
Doc.concat [attrs; print_mod_type ~state mod_type cmt_tbl]
808808
in
809809
print_comments doc cmt_tbl cmt_loc
810+
| [(attrs, {Location.txt = "*"; loc}, None)] ->
811+
let attrs = print_attributes ~state attrs cmt_tbl in
812+
let doc = Doc.concat [attrs; Doc.text "()"] in
813+
print_comments doc cmt_tbl loc
810814
| params ->
811815
Doc.group
812816
(Doc.concat
@@ -834,8 +838,10 @@ and print_mod_type ~state mod_type cmt_tbl =
834838
print_attributes ~state attrs cmt_tbl
835839
in
836840
let lbl_doc =
837-
if lbl.Location.txt = "_" || lbl.txt = "*" then
838-
Doc.nil
841+
if lbl.Location.txt = "_" then Doc.nil
842+
else if lbl.txt = "*" then
843+
let doc = Doc.text "()" in
844+
print_comments doc cmt_tbl lbl.loc
839845
else
840846
let doc = Doc.text lbl.txt in
841847
print_comments doc cmt_tbl lbl.loc

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ module React = {
33

44
let render = () => Js.log("foo")
55
}
6+
7+
module Make: () => S = (_: Config, ()) => {}
8+
module rec Make: (Config, ()) => S = (Config: Config, ()): S => {}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ module React = {
33

44
let render = () => Js.log("foo")
55
}
6+
7+
module Make: () => S = (Config, ()) => {}
8+
module rec Make: (Config, ()) => S = (Config: Config, ()): S => {}

0 commit comments

Comments
 (0)