Skip to content

Commit fec3b23

Browse files
committed
follow synonyms when #show-ing module types
see ocaml#11533
1 parent 06a1ad7 commit fec3b23

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

testsuite/tests/tool-toplevel/show.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type 'a t += A : int t
132132
#show Set.OrderedType;;
133133
[%%expect {|
134134
module type OrderedType = Set.OrderedType
135+
module type OrderedType = sig type t val compare : t -> t -> int end
135136
|}];;
136137

137138
module U = Stdlib.Unit;;
@@ -159,7 +160,11 @@ module U :
159160
end
160161
|}];;
161162

163+
(* Similar stuttering here now that (post-11533) module type synonyms
164+
are also followed. *)
162165
#show OT;;
163166
[%%expect {|
164167
module type OT = Set.OrderedType
168+
module type OT = Set.OrderedType
169+
module type OT = sig type t val compare : t -> t -> int end
165170
|}];;

toplevel/topdirs.ml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,21 @@ let () =
563563
let () =
564564
reg_show_prim "show_module_type"
565565
(fun env loc id lid ->
566-
let _path, desc = Env.lookup_modtype ~loc lid env in
567-
[ Sig_modtype (id, desc, Exported) ]
566+
let path, mtd = Env.lookup_modtype ~loc lid env in
567+
let id = match path with
568+
| Pident id -> id
569+
| _ -> id
570+
in
571+
let rec accum_defs mtd acc =
572+
let acc = Sig_modtype (id, mtd, Exported) :: acc in
573+
match mtd.mtd_type with
574+
| Some (Mty_ident path) ->
575+
let mtd = Env.find_modtype path env in
576+
accum_defs mtd acc
577+
| None | Some (Mty_alias _ | Mty_signature _ | Mty_functor _) ->
578+
List.rev acc
579+
in
580+
accum_defs mtd []
568581
)
569582
"Print the signature of the corresponding module type."
570583

0 commit comments

Comments
 (0)