From d47e613b736cc25629aabc1c8ef91795e265eacb Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Wed, 4 Oct 2023 17:52:07 -0700 Subject: [PATCH] fix: record constraint pattern (#2725) undefined --- CHANGES.md | 2 ++ flake.lock | 14 +++++++------- src/reason-parser/reason_pprint_ast.ml | 11 ++++++++++- test/wrapping-re.t/input.re | 5 ++++- test/wrapping-re.t/run.t | 2 ++ 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6be902d35..7cb4853de 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/flake.lock b/flake.lock index 43e4fadc6..1f84b9ff7 100644 --- a/flake.lock +++ b/flake.lock @@ -41,11 +41,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1695149910, - "narHash": "sha256-rzpTFXX0yVO02Y2l9J+9zcnHEEWJ0/uKB74aBoW8PUs=", + "lastModified": 1696357929, + "narHash": "sha256-FJ8SgB4rgAXD1qjplpWAr14mudSSnOrShjbuhC9w2M0=", "owner": "nix-ocaml", "repo": "nix-overlays", - "rev": "c9e78a97c6dc5ce6ec9a96aaabe74e21f2a485d8", + "rev": "6fe39115c01d42e452f837ed38ae7a244a78f699", "type": "github" }, "original": { @@ -56,17 +56,17 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1695043561, - "narHash": "sha256-ajrDIUJA5RB6Y2I1G4suDhiDMJuwg1WarNuasshRobE=", + "lastModified": 1696303624, + "narHash": "sha256-mL5k0klTRO3/59HCI8U1QujzGsnyL0GtQI+5XABXDNA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "089313d7c7c864b21648d78fb8700062dafab1f2", + "rev": "4d29250d5b55fe14280906afad7afacd910850b8", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "089313d7c7c864b21648d78fb8700062dafab1f2", + "rev": "4d29250d5b55fe14280906afad7afacd910850b8", "type": "github" } }, diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml index 4784535d6..ba092976a 100644 --- a/src/reason-parser/reason_pprint_ast.ml +++ b/src/reason-parser/reason_pprint_ast.ml @@ -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 diff --git a/test/wrapping-re.t/input.re b/test/wrapping-re.t/input.re index 01fe0339f..13a9e533b 100644 --- a/test/wrapping-re.t/input.re +++ b/test/wrapping-re.t/input.re @@ -1486,7 +1486,7 @@ let funcOnSomeRecord /* With two args */ let funcOnSomeConstructorHi - (SomeConstructorHi(x,y), secondArg) = + (SomeConstructorHi(x,y), secondArg) = x + y; let funcOnSomeRecord @@ -1982,3 +1982,6 @@ fooSpreadES6List([ "more tests", ...x ]); + +let { foo: (_: int), } = 2; + diff --git a/test/wrapping-re.t/run.t b/test/wrapping-re.t/run.t index c8823ac54..29ce4349f 100644 --- a/test/wrapping-re.t/run.t +++ b/test/wrapping-re.t/run.t @@ -2904,3 +2904,5 @@ Format wrapping in .re files "more tests", ...x, ]); + + let {foo: (_: int)} = 2;