Skip to content

Commit

Permalink
Bugfix for Ctype.nondep_type (#1059)
Browse files Browse the repository at this point in the history
  • Loading branch information
stedolan authored and poechsel committed Jan 12, 2023
1 parent 4301b33 commit 15bc880
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
17 changes: 17 additions & 0 deletions ocaml/testsuite/tests/typing-signatures/nondep_regression.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(* TEST
* expect
*)

type 'a seq = 'a list

module Make (A : sig type t end) = struct
type t = A.t seq
end

module H = Make (struct type t end)

[%%expect{|
type 'a seq = 'a list
module Make : functor (A : sig type t end) -> sig type t = A.t seq end
module H : sig type t end
|}]
1 change: 1 addition & 0 deletions ocaml/typing/btype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module TransientTypeHash = Hashtbl.Make(TransientTypeOps)
module TypeHash = struct
include TransientTypeHash
let add hash = wrap_repr (add hash)
let remove hash = wrap_repr (remove hash)
let find hash = wrap_repr (find hash)
let iter f = TransientTypeHash.iter (wrap_type_expr f)
end
Expand Down
1 change: 1 addition & 0 deletions ocaml/typing/btype.mli
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ end
module TypeHash : sig
include Hashtbl.S with type key = transient_expr
val add: 'a t -> type_expr -> 'a -> unit
val remove : 'a t -> type_expr -> unit
val find: 'a t -> type_expr -> 'a
val iter: (type_expr -> 'a -> unit) -> 'a t -> unit
end
Expand Down
12 changes: 8 additions & 4 deletions ocaml/typing/ctype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5420,7 +5420,7 @@ let rec nondep_type_rec ?(expand_private=false) env ids ty =
with Not_found ->
let ty' = newgenstub ~scope:(get_scope ty) in
TypeHash.add nondep_hash ty ty';
let desc =
match
match get_desc ty with
| Tconstr(p, tl, _abbrev) as desc ->
begin try
Expand Down Expand Up @@ -5481,9 +5481,13 @@ let rec nondep_type_rec ?(expand_private=false) env ids ty =
| _ -> Tvariant row
end
| desc -> copy_type_desc (nondep_type_rec env ids) desc
in
Transient_expr.set_stub_desc ty' desc;
ty'
with
| desc ->
Transient_expr.set_stub_desc ty' desc;
ty'
| exception e ->
TypeHash.remove nondep_hash ty;
raise e

let nondep_type env id ty =
try
Expand Down

0 comments on commit 15bc880

Please sign in to comment.