Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: record constraint pattern #2725

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Print structure items extension nodes correctly inside modules (@anmonteiro,
[#2723](https://github.com/reasonml/reason/pull/2723))
- Print wrapped type constraint on record patterns (@anmonteiro,
[#2725](https://github.com/reasonml/reason/pull/2725))

## 3.10.0

Expand Down
14 changes: 7 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5760,7 +5760,16 @@ let printer = object(self:'self)
(* works with module prefix too: {ReasonReact.state: state as prevState} becomes {ReasonReact.state as prevState *)
makeList ~sep:(Sep " ") [self#longident_loc li; atom "as"; atom aliasIdent]
| _ ->
label ~space:true (makeList [self#longident_loc li; atom ":"]) (self#pattern p)
let pattern =
let formatted = self#pattern p in
let wrap =
match p.ppat_desc with
| Ppat_constraint (_, _) -> Some("(", ")")
| _ -> None
in
makeList ~inline:(true, true) ?wrap [ formatted ]
in
label ~space:true (makeList [self#longident_loc li; atom ":"]) pattern
in
let rows = (List.map longident_x_pattern l)@(
match closed with
Expand Down
5 changes: 4 additions & 1 deletion test/wrapping-re.t/input.re
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ let funcOnSomeRecord

/* With two args */
let funcOnSomeConstructorHi
(SomeConstructorHi(x,y), secondArg) =
(SomeConstructorHi(x,y), secondArg) =
x + y;

let funcOnSomeRecord
Expand Down Expand Up @@ -1982,3 +1982,6 @@ fooSpreadES6List([
"more tests",
...x
]);