summaryrefslogtreecommitdiff
path: root/testsuite/tests/typing-misc/unique_names_in_unification.ml
blob: 18a69f32bd25f2f5b20e52f66cfa15918a4088b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(* TEST
   * expect
 *)
type t = A
let x = A
module M = struct
  type t = B
  let f: t -> t = fun B -> x
end;;

[%%expect{|
type t = A
val x : t = A
Line 5, characters 27-28:
5 |   let f: t -> t = fun B -> x
                               ^
Error: This expression has type t/2 but an expression was expected of type t
       Line 4, characters 2-12:
         Definition of type t
       Line 1, characters 0-10:
         Definition of type t/2
|}]

module M = struct type t = B end
let y = M.B
module N = struct
  module M = struct
     type t = C
  end
  let f : M.t -> M.t = fun M.C -> y
end;;

[%%expect{|
module M : sig type t = B end
val y : M.t = M.B
Line 7, characters 34-35:
7 |   let f : M.t -> M.t = fun M.C -> y
                                      ^
Error: This expression has type M/2.t but an expression was expected of type
         M.t
       Lines 4-6, characters 2-5:
         Definition of module M
       Line 1, characters 0-32:
         Definition of module M/2
|}]

type t = D
let f: t -> t = fun D -> x;;


[%%expect{|
type t = D
Line 2, characters 25-26:
2 | let f: t -> t = fun D -> x;;
                             ^
Error: This expression has type t/2 but an expression was expected of type t
       Line 1, characters 0-10:
         Definition of type t
       Line 1, characters 0-10:
         Definition of type t/2
|}]

type ttt
type ttt = A of ttt | B of uuu
and uuu  = C of uuu | D of ttt;;
[%%expect{|
type ttt
type ttt = A of ttt | B of uuu
and uuu = C of uuu | D of ttt
|}]

type nonrec ttt = X of ttt
let x: ttt = let rec y = A y in y;;
[%%expect{|
type nonrec ttt = X of ttt
Line 2, characters 32-33:
2 | let x: ttt = let rec y = A y in y;;
                                    ^
Error: This expression has type ttt/2 but an expression was expected of type
         ttt
       Line 1, characters 0-26:
         Definition of type ttt
       Line 2, characters 0-30:
         Definition of type ttt/2
|}]