Skip to content

Commit bc4b7f4

Browse files
authored
Fix formatter handling of wildcard pattern matching in record (rescript-lang#7224)
* Fix formatter handling of wildcard pattern matching in record with no fields specified * Update CHANGELOG
1 parent e5263bd commit bc4b7f4

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
- Fix bug where a ref assignment is moved ouside a conditional. https://github.com/rescript-lang/rescript/pull/7176
3535
- Fix nullable to opt conversion. https://github.com/rescript-lang/rescript/pull/7193
3636
- Raise error when defining external React components with `@react.componentWithProps`. https://github.com/rescript-lang/rescript/pull/7217
37+
- Fix formatter handling of wildcard in pattern matching records with no fields specified. https://github.com/rescript-lang/rescript/pull/7224
3738

3839
#### :house: Internal
3940

compiler/syntax/src/res_printer.ml

+2
Original file line numberDiff line numberDiff line change
@@ -2420,6 +2420,8 @@ and print_pattern ~state (p : Parsetree.pattern) cmt_tbl =
24202420
Doc.soft_line;
24212421
Doc.rbrace;
24222422
]
2423+
| Ppat_record ([], Open) ->
2424+
Doc.concat [Doc.lbrace; Doc.text "_"; Doc.rbrace]
24232425
| Ppat_record (rows, open_flag) ->
24242426
Doc.group
24252427
(Doc.concat

tests/syntax_tests/data/printer/pattern/expected/record.res.txt

+11
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,14 @@ let get_age3 = ({age: module(P: S), name: _}) => age2
114114
let get_age3 = ({age: exception Exit, name: _}) => age2
115115

116116
let get_age3 = ({age: %raw("__GC"), name: _}) => age2
117+
118+
let get_age3 = ({age, _}) => age
119+
let get_age3 = ({_}) => ""
120+
let get_age3 = () =>
121+
switch x {
122+
| {age, _} => age
123+
}
124+
let get_age3 = () =>
125+
switch x {
126+
| {_} => ""
127+
}

tests/syntax_tests/data/printer/pattern/record.res

+11
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,14 @@ let get_age3 = ({age: module(P: S), name: _}) => age2
5858
let get_age3 = ({age: exception Exit, name: _}) => age2
5959

6060
let get_age3 = ({age: %raw("__GC"), name: _}) => age2
61+
62+
let get_age3 = ({age, _}) => age
63+
let get_age3 = ({_}) => ""
64+
let get_age3 = () =>
65+
switch x {
66+
| {age, _} => age
67+
}
68+
let get_age3 = () =>
69+
switch x {
70+
| {_} => ""
71+
}

0 commit comments

Comments
 (0)