Skip to content

Commit

Permalink
fix: record constraint pattern (#2725)
Browse files Browse the repository at this point in the history
undefined
  • Loading branch information
anmonteiro authored Oct 5, 2023
1 parent f92f7ec commit d47e613
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
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
]);

let { foo: (_: int), } = 2;

2 changes: 2 additions & 0 deletions test/wrapping-re.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2904,3 +2904,5 @@ Format wrapping in .re files
"more tests",
...x,
]);

let {foo: (_: int)} = 2;

0 comments on commit d47e613

Please sign in to comment.