Skip to content

Commit 6f50e73

Browse files
shulhicknitt
authored andcommitted
Fix formatter handling of wildcard pattern matching in record (#7224)
1 parent e011b06 commit 6f50e73

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
@@ -23,6 +23,7 @@
2323
- Handle absolute file paths in gentype. https://github.com/rescript-lang/rescript-compiler/pull/7111
2424
- Fix "rescript format" with many files. https://github.com/rescript-lang/rescript-compiler/pull/7081
2525
- Fix exponential notation syntax. https://github.com/rescript-lang/rescript/pull/7174
26+
- Fix formatter handling of wildcard in pattern matching records with no fields specified. https://github.com/rescript-lang/rescript/pull/7224
2627

2728
#### :house: Internal
2829

jscomp/syntax/src/res_printer.ml

+2
Original file line numberDiff line numberDiff line change
@@ -2377,6 +2377,8 @@ and printPattern ~state (p : Parsetree.pattern) cmtTbl =
23772377
Doc.group (Doc.concat [variantName; argsDoc])
23782378
| Ppat_type ident ->
23792379
Doc.concat [Doc.text "#..."; printIdentPath ident cmtTbl]
2380+
| Ppat_record ([], Open) ->
2381+
Doc.concat [Doc.lbrace; Doc.text "_"; Doc.rbrace]
23802382
| Ppat_record (rows, openFlag) ->
23812383
Doc.group
23822384
(Doc.concat

jscomp/syntax/tests/printer/pattern/expected/record.res.txt

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

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

jscomp/syntax/tests/printer/pattern/record.res

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

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

0 commit comments

Comments
 (0)