diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml index a1ed911ea..2abdaba09 100644 --- a/src/reason-parser/reason_pprint_ast.ml +++ b/src/reason-parser/reason_pprint_ast.ml @@ -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 -> @@ -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 @@ -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) -> diff --git a/test/modules.t/input.re b/test/modules.t/input.re index 949967da2..2e953779f 100644 --- a/test/modules.t/input.re +++ b/test/modules.t/input.re @@ -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" ]; +} diff --git a/test/modules.t/run.t b/test/modules.t/run.t index cb19ba460..9311b0434 100644 --- a/test/modules.t/run.t +++ b/test/modules.t/run.t @@ -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 */