diff --git a/testlabl/poly.exp b/testlabl/poly.exp index c51b9cdff..f3e36070c 100644 --- a/testlabl/poly.exp +++ b/testlabl/poly.exp @@ -249,4 +249,6 @@ Type 'a u t should be an instance of g t type 'a v = 'a u t constraint 'a = int # Characters 38-58: In the definition of v, type 'a list u should be 'a u +# type 'a t = 'a +type 'a u = A of 'a t # diff --git a/testlabl/poly.exp2 b/testlabl/poly.exp2 index dbb61ab41..416dce1e8 100644 --- a/testlabl/poly.exp2 +++ b/testlabl/poly.exp2 @@ -256,4 +256,6 @@ Type 'a u t should be an instance of g t type 'a v = 'a u t constraint 'a = int # Characters 38-58: In the definition of v, type 'a list u should be 'a u +# type 'a t = 'a +type 'a u = A of 'a t # diff --git a/testlabl/poly.ml b/testlabl/poly.ml index 7f7986ee2..f58f61377 100644 --- a/testlabl/poly.ml +++ b/testlabl/poly.ml @@ -409,3 +409,7 @@ type 'a u = 'a and 'a v = 'a u t constraint 'a = int;; (* Example of wrong expansion *) type 'a u = < m : 'a v > and 'a v = 'a list u;; + +(* PR#1744: Ctype.matches *) +type 'a t = 'a +type 'a u = A of 'a t;; diff --git a/typing/ctype.ml b/typing/ctype.ml index a2b1b2b09..7a9066deb 100644 --- a/typing/ctype.ml +++ b/typing/ctype.ml @@ -2092,11 +2092,11 @@ let rigidify ty = unmark_type ty; !vars -let all_distinct_vars vars = +let all_distinct_vars env vars = let tyl = ref [] in List.for_all (fun ty -> - let ty = repr ty in + let ty = expand_head env ty in if List.memq ty !tyl then false else (tyl := ty :: !tyl; ty.desc = Tvar)) vars @@ -2105,7 +2105,7 @@ let matches env ty ty' = let snap = snapshot () in let vars = rigidify ty in let ok = - try unify env ty ty'; all_distinct_vars vars + try unify env ty ty'; all_distinct_vars env vars with Unify _ -> false in backtrack snap; diff --git a/typing/ctype.mli b/typing/ctype.mli index 766476d44..ae4f15dd9 100644 --- a/typing/ctype.mli +++ b/typing/ctype.mli @@ -153,7 +153,7 @@ val moregeneral: Env.t -> bool -> type_expr -> type_expr -> bool val rigidify: type_expr -> type_expr list (* "Rigidify" a type and return its type variable *) -val all_distinct_vars: type_expr list -> bool +val all_distinct_vars: Env.t -> type_expr list -> bool (* Check those types are all distinct type variables *) val matches : Env.t -> type_expr -> type_expr -> bool (* Same as [moregeneral false], implemented using the two above