Skip to content

Commit

Permalink
handle external%foo in module types
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Jul 21, 2024
1 parent 5451aa3 commit 93b5756
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7174,17 +7174,6 @@ let printer = object(self:'self)
(self#class_self_pattern_and_structure cs)
method signature signatureItems =
let signature_item item =
match item.psig_desc with
| Psig_extension ((extension, PSig [item]), _attrs) ->
begin match item.psig_desc with
(* In case of a value or `external`, the extension gets inlined
`let%private a = 1` *)
| Psig_value ({ pval_prim = [_]; _ } as vd) -> self#primitive_declaration ~extension vd
| _ -> self#signature_item item
end
| _ -> self#signature_item item
in
match signatureItems with
| [] -> atom ""
| first::_ as signatureItems ->
Expand All @@ -7193,7 +7182,7 @@ let printer = object(self:'self)
let loc_end = last.psig_loc.loc_end in
let items =
groupAndPrint
~xf:signature_item
~xf:self#signature_item
~getLoc:(fun x -> x.psig_loc)
~comments:self#comments
signatureItems
Expand All @@ -7207,7 +7196,18 @@ let printer = object(self:'self)
~sep:(SepFinal (";", ";"))
items)
method signature_item x : Layout.t =
method signature_item item : Layout.t =
match item.psig_desc with
| Psig_extension ((extension, PSig [item]), _attrs) ->
begin match item.psig_desc with
(* In case of a value or `external`, the extension gets inlined
`let%private a = 1` *)
| Psig_value ({ pval_prim = [_]; _ } as vd) -> self#primitive_declaration ~extension vd
| _ -> self#signature_item' item
end
| _ -> self#signature_item' item
method signature_item' x : Layout.t =
let item: Layout.t =
match x.psig_desc with
| Psig_type (rf, l) ->
Expand Down
13 changes: 13 additions & 0 deletions test/modules.t/input.re
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,16 @@ let y = Promise.Ops.(
Js.Promise.resolve(x * 2)
)
);

module WithExternalExtension: {
external%foo bar: string => string = "";
[%%foo: external bar: int => int = "hello" ];
} = {
external%foo bar: string => string = "";
[%%foo external bar: int => int = "hello" ];
}

module type TypeWithExternalExtension = {
external%foo bar: string => string = "";
[%%foo: external bar: int => int = "hello" ];
}
13 changes: 13 additions & 0 deletions test/modules.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -676,4 +676,17 @@ Format modules
Js.Promise.resolve(x * 2);
)
);

module WithExternalExtension: {
external%foo bar: string => string;
external%foo bar: int => int = "hello";
} = {
external%foo bar: string => string;
external%foo bar: int => int = "hello";
};

module type TypeWithExternalExtension = {
external%foo bar: string => string;
external%foo bar: int => int = "hello";
};
/* From http://stackoverflow.com/questions/1986374/ higher-order-type-constructors-and-functors-in-ocaml */

0 comments on commit 93b5756

Please sign in to comment.