Skip to content

Commit

Permalink
follow synonyms when #show-ing module types
Browse files Browse the repository at this point in the history
see #11533
  • Loading branch information
gasche committed Dec 1, 2022
1 parent 06a1ad7 commit fec3b23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions testsuite/tests/tool-toplevel/show.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;;
Expand Down Expand Up @@ -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
|}];;
17 changes: 15 additions & 2 deletions toplevel/topdirs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down

0 comments on commit fec3b23

Please sign in to comment.