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: print module expr attributes #2803

Merged
merged 3 commits into from
Oct 20, 2024
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 @@ -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

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.

13 changes: 11 additions & 2 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. *)
Expand All @@ -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 =
Expand All @@ -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 =
Expand Down
14 changes: 14 additions & 0 deletions test/modules.t/input.re
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
()
};
15 changes: 15 additions & 0 deletions test/modules.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Loading