summaryrefslogtreecommitdiff
path: root/testsuite/tests/typing-extensions/disambiguation.ml
blob: feae4c711603fc46427a4a66662f56d22e0a6860 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
(* TEST
   * expect
*)
(** Test type-directed disambiguation and spellchecker hints *)

type t = ..
type t += Alpha | Aleph

module M = struct
  type w = ..
  type w += Alpha | Beta ;;
  type t += Beth
end;;

module F(X:sig end) = struct type u = .. type t += Gamma type u += Gamme end;;
module X = struct end;;
[%%expect {|
type t = ..
type t += Alpha | Aleph
module M : sig type w = .. type w += Alpha | Beta type t += Beth end
module F :
  functor (X : sig end) ->
    sig type u = .. type t += Gamma type u += Gamme end
module X : sig end
|}]

let x: t = Alph;;
[%%expect {|
Line 1, characters 11-15:
1 | let x: t = Alph;;
               ^^^^
Error: This variant expression is expected to have type t
       The constructor Alph does not belong to type t
Hint: Did you mean Aleph or Alpha?
|}]

open M;;
let y : w = Alha;;
[%%expect {|
Line 2, characters 12-16:
2 | let y : w = Alha;;
                ^^^^
Error: This variant expression is expected to have type M.w
       The constructor Alha does not belong to type M.w
Hint: Did you mean Alpha?
|}]

let z: t = Bet;;
[%%expect {|
Line 1, characters 11-14:
1 | let z: t = Bet;;
               ^^^
Error: This variant expression is expected to have type t
       The constructor Bet does not belong to type t
Hint: Did you mean Beth?
|}]


module N = F(X);;
open N
let g = (Gamm:t);;
[%%expect {|
module N : sig type u = F(X).u = .. type t += Gamma type u += Gamme end
Line 3, characters 9-13:
3 | let g = (Gamm:t);;
             ^^^^
Error: This variant expression is expected to have type t
       The constructor Gamm does not belong to type t
Hint: Did you mean Gamma?
|}];;

raise Not_Found;;
[%%expect {|
Line 1, characters 6-15:
1 | raise Not_Found;;
          ^^^^^^^^^
Error: This variant expression is expected to have type exn
       The constructor Not_Found does not belong to type exn
Hint: Did you mean Not_found?
|}]

(** Aliasing *)
type r = ..;;
module M = struct
  type t = r = ..
  type s = t = ..
  module N = struct
    type u = s = ..
    type u += Foo
  end
end
open M.N;;

type exn += Foo;;

let x : r = Foo;;
[%%expect {|
type r = ..
module M :
  sig
    type t = r = ..
    type s = t = ..
    module N : sig type u = s = .. type u += Foo end
  end
type exn += Foo
val x : r = M.N.Foo
|}]

(** Closed open extensible type support *)

module M : sig
  type t = private ..
  type t += Aleph
end = struct
  type t = ..
  type t += Aleph
end;;
open M;;

type exn += Aleph ;;
[%%expect {|
module M : sig type t = private .. type t += Aleph end
type exn += Aleph
|}]

let x : t = Aleph;;
[%%expect {|
val x : M.t = M.Aleph
|}]

module F(X: sig type t = .. end ) = struct type X.t+= Beth end
module X = struct type t = .. end
module FX = F(X) open FX
type exn += Beth;;
let x : X.t = Beth;;
[%%expect {|
module F : functor (X : sig type t = .. end) -> sig type X.t += Beth end
module X : sig type t = .. end
module FX : sig type X.t += Beth end
type exn += Beth
val x : X.t = <extension>
|}]

(** Aliasing *)

type x = ..
type x += Alpha
module P = struct type p = x end

let x: P.p = Alha;;
[%%expect {|
type x = ..
type x += Alpha
module P : sig type p = x end
Line 7, characters 13-17:
7 | let x: P.p = Alha;;
                 ^^^^
Error: This variant expression is expected to have type P.p
       The constructor Alha does not belong to type x
Hint: Did you mean Alpha?
|}]

module M = struct type t = .. type t += T end
module N = struct type s = M.t end
let y: N.s = T ;;
[%%expect {|
module M : sig type t = .. type t += T end
module N : sig type s = M.t end
Line 3, characters 13-14:
3 | let y: N.s = T ;;
                 ^
Error: This variant expression is expected to have type N.s
       The constructor T does not belong to type M.t
|}]

(** Pattern matching *)
type x = ..
type x += A | B
type u = A | B
module M = struct type y = .. type y+= A|B end
open M
let f: x -> int = function A -> 1 | B -> 2 | _ -> 0;;
[%%expect {|
type x = ..
type x += A | B
type u = A | B
module M : sig type y = .. type y += A | B  end
val f : x -> int = <fun>
|}]

(** Local exception *)
let x =
  let exception Local in
  raise Locl;;
[%%expect {|
Line 3, characters 8-12:
3 |   raise Locl;;
            ^^^^
Error: This variant expression is expected to have type exn
       The constructor Locl does not belong to type exn
Hint: Did you mean Local?
|}]

let x =
  let exception Local in
  let module M = struct type t = .. type t+= Local end in
  let open M in
  (Local:exn);;
[%%expect{|
val x : exn = Local
|}
]

(** Path capture *)
module M = struct type t = .. type t += T end
open M
let f = (=) M.T
module M = struct type t = .. type t += S end
open M
let y = f T ;;
[%%expect {|
module M : sig type t = .. type t += T end
val f : M.t -> bool = <fun>
module M : sig type t = .. type t += S end
val y : bool = true
|}]

(** Amniguity warning *)
[@@@warning "+41"];;
type a = Unique
type t = ..
type t += Unique
module M = struct type s = .. type s+= Unique end open M
type b = Unique
let x = Unique;;
[%%expect {|
type a = Unique
type t = ..
type t += Unique
module M : sig type s = .. type s += Unique end
type b = Unique
Line 7, characters 8-14:
7 | let x = Unique;;
            ^^^^^^
Warning 41: Unique belongs to several types: b M.s t a
The first one was selected. Please disambiguate if this is wrong.
val x : b = Unique
|}]