summaryrefslogtreecommitdiff
path: root/testsuite/tests/typing-warnings/open_warnings.ml
blob: de810ae1069f45ec4f7b5b18de119d9fd7be1c81 (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
(* TEST
   flags = " -w +A-41-42-18"
   * expect
*)
module T1 : sig end = struct
  module M = struct type t end  (* unused type t *)
  open M  (* unused open *)
end;;
[%%expect{|
Line 2, characters 20-26:
2 |   module M = struct type t end  (* unused type t *)
                        ^^^^^^
Warning 34 [unused-type-declaration]: unused type t.

Line 3, characters 2-8:
3 |   open M  (* unused open *)
      ^^^^^^
Warning 33 [unused-open]: unused open M.

module T1 : sig end
|}]


module T2 : sig type s end = struct
  module M = struct type t end
  open M  (* used by line below *)
  type s = t
end;;
[%%expect{|
module T2 : sig type s end
|}]

module T3 : sig end = struct
  type t0 = A  (* unused type and constructor *)
  module M = struct type t = A end
  open M (* used by line below; shadow constructor A *)
  let _ = A (* A belongs to several types *)
end;;
[%%expect{|
Line 4, characters 2-8:
4 |   open M (* used by line below; shadow constructor A *)
      ^^^^^^
Warning 45 [open-shadow-label-constructor]: this open statement shadows the constructor A (which is later used)

Line 2, characters 2-13:
2 |   type t0 = A  (* unused type and constructor *)
      ^^^^^^^^^^^
Warning 34 [unused-type-declaration]: unused type t0.

Line 2, characters 12-13:
2 |   type t0 = A  (* unused type and constructor *)
                ^
Warning 37 [unused-constructor]: unused constructor A.

module T3 : sig end
|}]

module T4 : sig end = struct
  type t0 = A
  module M = struct type t = A end (* unused type and constructor *)
  open M (* unused open; no shadowing (A below refers to the one in t0) *)
  let _ : t0 = A (* disambiguation used *)
end;;
[%%expect{|
Line 3, characters 20-30:
3 |   module M = struct type t = A end (* unused type and constructor *)
                        ^^^^^^^^^^
Warning 34 [unused-type-declaration]: unused type t.

Line 3, characters 29-30:
3 |   module M = struct type t = A end (* unused type and constructor *)
                                 ^
Warning 37 [unused-constructor]: unused constructor A.

Line 4, characters 2-8:
4 |   open M (* unused open; no shadowing (A below refers to the one in t0) *)
      ^^^^^^
Warning 33 [unused-open]: unused open M.

module T4 : sig end
|}]

module T5 : sig end = struct
  type t0 = A (* unused type and constructor *)
  module M = struct type t = A end
  open M (* shadow constructor A *)
  let _ : t = A
end;;
[%%expect{|
Line 4, characters 2-8:
4 |   open M (* shadow constructor A *)
      ^^^^^^
Warning 45 [open-shadow-label-constructor]: this open statement shadows the constructor A (which is later used)

Line 2, characters 2-13:
2 |   type t0 = A (* unused type and constructor *)
      ^^^^^^^^^^^
Warning 34 [unused-type-declaration]: unused type t0.

Line 2, characters 12-13:
2 |   type t0 = A (* unused type and constructor *)
                ^
Warning 37 [unused-constructor]: unused constructor A.

module T5 : sig end
|}]


module T1_bis : sig end = struct
  module M = struct type t end  (* unused type t *)
  open! M  (* unused open *)
end;;
[%%expect{|
Line 2, characters 20-26:
2 |   module M = struct type t end  (* unused type t *)
                        ^^^^^^
Warning 34 [unused-type-declaration]: unused type t.

Line 3, characters 2-9:
3 |   open! M  (* unused open *)
      ^^^^^^^
Warning 66 [unused-open-bang]: unused open! M.

module T1_bis : sig end
|}]

module T2_bis : sig type s end = struct
  module M = struct type t end
  open! M  (* used by line below *)
  type s = t
end;;
[%%expect{|
module T2_bis : sig type s end
|}]

module T3_bis : sig end = struct
  type t0 = A  (* unused type and constructor *)
  module M = struct type t = A end
  open! M (* used by line below; shadow constructor A (disabled) *)
  let _ = A (* A belongs to several types *)
end;;
[%%expect{|
Line 2, characters 2-13:
2 |   type t0 = A  (* unused type and constructor *)
      ^^^^^^^^^^^
Warning 34 [unused-type-declaration]: unused type t0.

Line 2, characters 12-13:
2 |   type t0 = A  (* unused type and constructor *)
                ^
Warning 37 [unused-constructor]: unused constructor A.

module T3_bis : sig end
|}]

module T4_bis : sig end = struct
  type t0 = A
  module M = struct type t = A end (* unused type and constructor *)
  open! M (* unused open; no shadowing (A below refers to the one in t0) *)
  let _ : t0 = A (* disambiguation used *)
end;;
[%%expect{|
Line 3, characters 20-30:
3 |   module M = struct type t = A end (* unused type and constructor *)
                        ^^^^^^^^^^
Warning 34 [unused-type-declaration]: unused type t.

Line 3, characters 29-30:
3 |   module M = struct type t = A end (* unused type and constructor *)
                                 ^
Warning 37 [unused-constructor]: unused constructor A.

Line 4, characters 2-9:
4 |   open! M (* unused open; no shadowing (A below refers to the one in t0) *)
      ^^^^^^^
Warning 66 [unused-open-bang]: unused open! M.

module T4_bis : sig end
|}]

module T5_bis : sig end = struct
  type t0 = A (* unused type and constructor *)
  module M = struct type t = A end
  open! M (* shadow constructor A (disabled) *)
  let _ : t = A
end;;
[%%expect{|
Line 2, characters 2-13:
2 |   type t0 = A (* unused type and constructor *)
      ^^^^^^^^^^^
Warning 34 [unused-type-declaration]: unused type t0.

Line 2, characters 12-13:
2 |   type t0 = A (* unused type and constructor *)
                ^
Warning 37 [unused-constructor]: unused constructor A.

module T5_bis : sig end
|}]

module T7 : sig end = struct
  (* GPR9170 *)
  module M = struct
    class type t = object end
  end
  module type S = sig
    open M
    val f: #t -> unit
  end
  let _ = fun ((module S : S)) -> S.f (object end)
end;;
[%%expect {|
module T7 : sig end
|}]

module T8 : sig end = struct
  (* GPR9170 *)
  module M = struct
    class t = object end
  end
  module type S = sig
    open M
    val f: #t -> unit
  end
  let _ = fun ((module S : S)) -> S.f (object end)
end;;
[%%expect {|
module T8 : sig end
|}]