Skip to content

Commit

Permalink
fix: print module expr attributes (#2803)
Browse files Browse the repository at this point in the history
* fix: print module expr attributes

* add tests + changelog entry

* update flakes?
  • Loading branch information
anmonteiro authored Oct 20, 2024
1 parent 9ec35aa commit dee8e63
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
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 */

0 comments on commit dee8e63

Please sign in to comment.