diff --git a/testsuite/tests/tool-toplevel/show.ml b/testsuite/tests/tool-toplevel/show.ml index 9e2665325d2..cff51c1c2b8 100644 --- a/testsuite/tests/tool-toplevel/show.ml +++ b/testsuite/tests/tool-toplevel/show.ml @@ -132,6 +132,7 @@ type 'a t += A : int t #show Set.OrderedType;; [%%expect {| module type OrderedType = Set.OrderedType +module type OrderedType = sig type t val compare : t -> t -> int end |}];; module U = Stdlib.Unit;; @@ -159,7 +160,11 @@ module U : end |}];; +(* Similar stuttering here now that (post-11533) module type synonyms + are also followed. *) #show OT;; [%%expect {| module type OT = Set.OrderedType +module type OT = Set.OrderedType +module type OT = sig type t val compare : t -> t -> int end |}];; diff --git a/toplevel/topdirs.ml b/toplevel/topdirs.ml index 97c1f1ae9ca..c47ea27e2ef 100644 --- a/toplevel/topdirs.ml +++ b/toplevel/topdirs.ml @@ -563,8 +563,21 @@ let () = let () = reg_show_prim "show_module_type" (fun env loc id lid -> - let _path, desc = Env.lookup_modtype ~loc lid env in - [ Sig_modtype (id, desc, Exported) ] + let path, mtd = Env.lookup_modtype ~loc lid env in + let id = match path with + | Pident id -> id + | _ -> id + in + let rec accum_defs mtd acc = + let acc = Sig_modtype (id, mtd, Exported) :: acc in + match mtd.mtd_type with + | Some (Mty_ident path) -> + let mtd = Env.find_modtype path env in + accum_defs mtd acc + | None | Some (Mty_alias _ | Mty_signature _ | Mty_functor _) -> + List.rev acc + in + accum_defs mtd [] ) "Print the signature of the corresponding module type."