Skip to content

Commit

Permalink
fix: record constraint pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Oct 5, 2023
1 parent f92f7ec commit 9120ad5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
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 9120ad5

Please sign in to comment.