diff --git a/CHANGES.md b/CHANGES.md index 9681ac34c..267318a82 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -34,6 +34,8 @@ [#2797](https://github.com/reasonml/reason/pull/2797)) - Fix formatting of callbacks with sequence expressions (@anmonteiro, [#2799](https://github.com/reasonml/reason/pull/2799)) +- Fix printing of attributes on module expressions (@anmonteiro, + [#2803](https://github.com/reasonml/reason/pull/2803)) ## 3.12.0 diff --git a/flake.lock b/flake.lock index 159298d7a..fe262993b 100644 --- a/flake.lock +++ b/flake.lock @@ -41,11 +41,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1728776100, - "narHash": "sha256-zCR+Nn9TIM3PHFLhdFG/fZIuqI1qfOTPRoz4Q75BOXI=", + "lastModified": 1729319520, + "narHash": "sha256-qJyYHqw7xiH+qcThWVzA8cdLSrdvS2P5pNOe+LI4sls=", "owner": "nix-ocaml", "repo": "nix-overlays", - "rev": "e2fae0adcc729eab831dc6aba3aac0859f60b2c0", + "rev": "f455dc8957da75567083129ac6deee772cdc01fe", "type": "github" }, "original": { @@ -56,17 +56,17 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1728752725, - "narHash": "sha256-nprzUVBuNtTMQVS8y92JKJS6Cpuo8JJpm2FXUW25F0Q=", + "lastModified": 1729308112, + "narHash": "sha256-Ap+cPeiluam2KFZO+OWuFTl/IkIJfyGYGMgkT2pVCRY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "fe17be0af8ff0de556b774b0fb176e96cb0ab080", + "rev": "61253596816c4cd65e2a0f474cbc0ac0c6e0f7cf", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "fe17be0af8ff0de556b774b0fb176e96cb0ab080", + "rev": "61253596816c4cd65e2a0f474cbc0ac0c6e0f7cf", "type": "github" } }, diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml index 8bb6d3c95..0ded1d597 100644 --- a/src/reason-parser/reason_pprint_ast.ml +++ b/src/reason-parser/reason_pprint_ast.ml @@ -9296,6 +9296,9 @@ let createFormatter () = *) method let_module_binding prefixText bindingName moduleExpr = + let { Reason_attributes.stdAttrs; _ } = + Reason_attributes.partitionAttributes moduleExpr.pmod_attributes + in let argsList, return = self#curriedFunctorPatternsAndReturnStruct moduleExpr in @@ -9317,6 +9320,7 @@ let createFormatter () = (Some (true, includingEqual)) ( [ self#moduleExpressionToFormattedApplicationItems unconstrainedRetTerm + |> self#attach_std_item_attrs stdAttrs ] , None ) (* Simple module with type no constraint, no functor args. *) @@ -9325,7 +9329,10 @@ let createFormatter () = prefixText bindingName None - ([ self#moduleExpressionToFormattedApplicationItems return ], None) + ( [ self#moduleExpressionToFormattedApplicationItems return + |> self#attach_std_item_attrs stdAttrs + ] + , None ) | _, _ -> (* A functor *) let argsWithConstraint, actualReturn = @@ -9346,7 +9353,9 @@ let createFormatter () = ~arrow:"=>" (makeList [ bindingName; atom " =" ]) argsWithConstraint - ( [ self#moduleExpressionToFormattedApplicationItems actualReturn ] + ( [ self#moduleExpressionToFormattedApplicationItems actualReturn + |> self#attach_std_item_attrs stdAttrs + ] , None ) method class_opening class_keyword name pci_virt ls = diff --git a/test/modules.t/input.re b/test/modules.t/input.re index 703259539..af2016a7f 100644 --- a/test/modules.t/input.re +++ b/test/modules.t/input.re @@ -572,3 +572,17 @@ module type t3 = t with module type x = { type t } module type t' = t with module type x := x module type t4 = t with module type x := { type t } + +module Foo = +[@someattr] +{ + type t = string +}; + +let x = { + let module Foo = + [@someattr] { + type t = string + }; + () +}; diff --git a/test/modules.t/run.t b/test/modules.t/run.t index 30978c3e3..5b1697752 100644 --- a/test/modules.t/run.t +++ b/test/modules.t/run.t @@ -752,4 +752,19 @@ Format modules t with module type x := { type t; }; + + module Foo = + [@someattr] + { + type t = string; + }; + + let x = { + module Foo = + [@someattr] + { + type t = string; + }; + (); + }; /* From http://stackoverflow.com/questions/1986374/ higher-order-type-constructors-and-functors-in-ocaml */