File tree 4 files changed +27
-11
lines changed
testsuite/tests/typing-poly
4 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -26,3 +26,17 @@ Line 1, characters 21-33:
26
26
Error : The universal type variable 'a cannot be generalized :
27
27
it escapes its scope .
28
28
|}]
29
+
30
+
31
+ (* * Check that renaming universal type variable is properly tracked
32
+ in printtyp *)
33
+
34
+ let f (x :<a:'a; b:'a. 'a> ) (y :<a:'a;b:'a> ) = x = y
35
+ [%% expect {|
36
+ Line 4 , characters 49-50 :
37
+ 4 | let f (x :<a:'a; b:'a. 'a> ) (y :<a:'a;b:'a> ) = x = y
38
+ ^
39
+ Error : This expression has type < a : 'a ; b : 'a >
40
+ but an expression was expected of type < a : 'a ; b : 'a0 . 'a0 >
41
+ The universal variable 'a0 would escape its scope
42
+ |}]
Original file line number Diff line number Diff line change @@ -66,7 +66,9 @@ module Unification_trace = struct
66
66
67
67
type 'a escape =
68
68
| Constructor of Path .t
69
- | Univ of string option
69
+ | Univ of type_expr
70
+ (* The type_expr argument of [Univ] is always a [Tunivar _],
71
+ we keep a [type_expr] to track renaming in {!Printtyp} *)
70
72
| Self
71
73
| Module_type of Path .t
72
74
| Equation of 'a
@@ -1826,9 +1828,9 @@ let occur_univar env ty =
1826
1828
true
1827
1829
then
1828
1830
match ty.desc with
1829
- Tunivar u ->
1831
+ Tunivar _ ->
1830
1832
if not (TypeSet. mem ty bound) then
1831
- raise Trace. (Unify [escape (Univ u )])
1833
+ raise Trace. (Unify [escape (Univ ty )])
1832
1834
| Tpoly (ty , tyl ) ->
1833
1835
let bound = List. fold_right TypeSet. add (List. map repr tyl) bound in
1834
1836
occur_rec bound ty
@@ -1879,8 +1881,8 @@ let univars_escape env univar_pairs vl ty =
1879
1881
Tpoly (t , tl ) ->
1880
1882
if List. exists (fun t -> TypeSet. mem (repr t) family) tl then ()
1881
1883
else occur t
1882
- | Tunivar u ->
1883
- if TypeSet. mem t family then raise Trace. (Unify [escape(Univ u )])
1884
+ | Tunivar _ ->
1885
+ if TypeSet. mem t family then raise Trace. (Unify [escape(Univ t )])
1884
1886
| Tconstr (_ , [] , _ ) -> ()
1885
1887
| Tconstr (p , tl , _ ) ->
1886
1888
begin try
Original file line number Diff line number Diff line change @@ -29,7 +29,9 @@ module Unification_trace: sig
29
29
(* * Scope escape related errors *)
30
30
type 'a escape =
31
31
| Constructor of Path .t
32
- | Univ of string option
32
+ | Univ of type_expr
33
+ (* * The type_expr argument of [Univ] is always a [Tunivar _],
34
+ we keep a [type_expr] to track renaming in {!Printtyp} *)
33
35
| Self
34
36
| Module_type of Path .t
35
37
| Equation of 'a
Original file line number Diff line number Diff line change @@ -1814,11 +1814,9 @@ let explain_escape intro ctx e =
1814
1814
| None -> ignore
1815
1815
| Some ctx -> dprintf " @[%t@;<1 2>%a@]" intro type_expr ctx in
1816
1816
match e with
1817
- | Trace. Univ Some u -> Some (
1818
- dprintf " %t@,The universal variable '%s would escape its scope"
1819
- pre u)
1820
- | Trace. Univ None ->
1821
- Some (dprintf " %t@,An universal variable would escape its scope" pre)
1817
+ | Trace. Univ u -> Some (
1818
+ dprintf " %t@,The universal variable %a would escape its scope"
1819
+ pre type_expr u)
1822
1820
| Trace. Constructor p -> Some (
1823
1821
dprintf
1824
1822
" %t@,@[The type constructor@;<1 2>%a@ would escape its scope@]"
You can’t perform that action at this time.
0 commit comments