blob: f87fa521d158929bacc332c13fc82739a517001c (
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
|
(* TEST
* expect
*)
(* with module *)
module type S = sig type t and s = t end;;
module type S' = S with type t := int;;
[%%expect{|
module type S = sig type t and s = t end
module type S' = sig type s = int end
|}];;
module type S = sig module rec M : sig end and N : sig end end;;
module type S' = S with module M := String;;
[%%expect{|
module type S = sig module rec M : sig end and N : sig end end
module type S' = sig module rec N : sig end end
|}];;
(* with module type *)
(*
module type S = sig module type T module F(X:T) : T end;;
module type T0 = sig type t end;;
module type S1 = S with module type T = T0;;
module type S2 = S with module type T := T0;;
module type S3 = S with module type T := sig type t = int end;;
module H = struct
include (Hashtbl : module type of Hashtbl with
type statistics := Hashtbl.statistics
and module type S := Hashtbl.S
and module Make := Hashtbl.Make
and module MakeSeeded := Hashtbl.MakeSeeded
and module type SeededS := Hashtbl.SeededS
and module type HashedType := Hashtbl.HashedType
and module type SeededHashedType := Hashtbl.SeededHashedType)
end;;
*)
(* A subtle problem appearing with -principal *)
type -'a t
class type c = object method m : [ `A ] t end;;
module M : sig val v : (#c as 'a) -> 'a end =
struct let v x = ignore (x :> c); x end;;
[%%expect{|
type -'a t
class type c = object method m : [ `A ] t end
module M : sig val v : (#c as 'a) -> 'a end
|}];;
(* PR#4838 *)
let id = let module M = struct end in fun x -> x;;
[%%expect{|
val id : 'a -> 'a = <fun>
|}];;
(* PR#4511 *)
let ko = let module M = struct end in fun _ -> ();;
[%%expect{|
val ko : 'a -> unit = <fun>
|}];;
(* PR#5993 *)
module M : sig type -'a t = private int end =
struct type +'a t = private int end
;;
[%%expect{|
Line 2, characters 2-37:
2 | struct type +'a t = private int end
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Signature mismatch:
Modules do not match:
sig type +'a t = private int end
is not included in
sig type -'a t = private int end
Type declarations do not match:
type +'a t = private int
is not included in
type -'a t = private int
Their variances do not agree.
|}];;
(* PR#6005 *)
module type A = sig type t = X of int end;;
type u = X of bool;;
module type B = A with type t = u;; (* fail *)
[%%expect{|
module type A = sig type t = X of int end
type u = X of bool
Line 3, characters 23-33:
3 | module type B = A with type t = u;; (* fail *)
^^^^^^^^^^
Error: This variant or record definition does not match that of type u
Constructors do not match:
X of bool
is not the same as:
X of int
The type bool is not equal to the type int
|}];;
(* PR#5815 *)
(* ---> duplicated exception name is now an error *)
module type S = sig exception Foo of int exception Foo of bool end;;
[%%expect{|
Line 1, characters 42-63:
1 | module type S = sig exception Foo of int exception Foo of bool end;;
^^^^^^^^^^^^^^^^^^^^^
Error: Multiple definition of the extension constructor name Foo.
Names must be unique in a given structure or signature.
|}];;
(* PR#6410 *)
module F(X : sig end) = struct let x = 3 end;;
F.x;; (* fail *)
[%%expect{|
module F : functor (X : sig end) -> sig val x : int end
Line 2, characters 0-3:
2 | F.x;; (* fail *)
^^^
Error: The module F is a functor, it cannot have any components
|}];;
type t = ..;;
[%%expect{|
type t = ..
|}];;
module M : sig type t += E end = struct type t += E of int end;;
[%%expect{|
Line 1, characters 33-62:
1 | module M : sig type t += E end = struct type t += E of int end;;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Signature mismatch:
Modules do not match:
sig type t += E of int end
is not included in
sig type t += E end
Extension declarations do not match:
type t += E of int
is not included in
type t += E
Constructors do not match:
E of int
is not the same as:
E
They have different arities.
|}];;
module M : sig type t += E of char end = struct type t += E of int end;;
[%%expect{|
Line 1, characters 41-70:
1 | module M : sig type t += E of char end = struct type t += E of int end;;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Signature mismatch:
Modules do not match:
sig type t += E of int end
is not included in
sig type t += E of char end
Extension declarations do not match:
type t += E of int
is not included in
type t += E of char
Constructors do not match:
E of int
is not the same as:
E of char
The type int is not equal to the type char
|}];;
module M : sig type t += C of int end = struct type t += E of int end;;
[%%expect{|
Line 1, characters 40-69:
1 | module M : sig type t += C of int end = struct type t += E of int end;;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Signature mismatch:
Modules do not match:
sig type t += E of int end
is not included in
sig type t += C of int end
The extension constructor `C' is required but not provided
|}];;
module M : sig
type t += E of { x : int }
end = struct
type t += E of int
end;;
[%%expect{|
Lines 3-5, characters 6-3:
3 | ......struct
4 | type t += E of int
5 | end..
Error: Signature mismatch:
Modules do not match:
sig type t += E of int end
is not included in
sig type t += E of { x : int; } end
Extension declarations do not match:
type t += E of int
is not included in
type t += E of { x : int; }
Constructors do not match:
E of int
is not the same as:
E of { x : int; }
The second uses inline records and the first doesn't.
|}];;
|