Skip to content

Commit 1e5d960

Browse files
committed
add more module type error cases
<!-- ps-id: d73095c3-be81-4a9c-8ad0-fddf33272dd4 -->
1 parent fceb670 commit 1e5d960

File tree

2 files changed

+360
-0
lines changed
  • src_test/ppx_deriving

2 files changed

+360
-0
lines changed

src_test/ppx_deriving/errors/run.t

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,183 @@ It's been fixed for later versions in https://github.com/ocaml/ocaml/pull/8541
117117
2 | type b = int
118118
3 | type a = string]
119119
Error: [] expected
120+
121+
Ptyp
122+
$ cat >test.ml <<EOF
123+
> [%%import: string]
124+
> EOF
125+
126+
$ dune build
127+
File "test.ml", line 1, characters 0-18:
128+
1 | [%%import: string]
129+
^^^^^^^^^^^^^^^^^^
130+
Error: PSig expected
131+
[1]
132+
133+
Inline module type declaration
134+
$ cat >test.ml <<EOF
135+
> module type Hashable = [%import: (module sig type t end)]
136+
> EOF
137+
138+
$ dune build
139+
File "test.ml", line 1, characters 41-55:
140+
1 | module type Hashable = [%import: (module sig type t end)]
141+
^^^^^^^^^^^^^^
142+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
143+
[1]
144+
145+
Functor
146+
$ cat >test.ml <<EOF
147+
> module type Foo = [%import: (module functor (M : sig end) -> sig end)]
148+
> EOF
149+
150+
$ dune build
151+
File "test.ml", line 1, characters 44-68:
152+
1 | module type Foo = [%import: (module functor (M : sig end) -> sig end)]
153+
^^^^^^^^^^^^^^^^^^^^^^^^
154+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
155+
[1]
156+
157+
Module type of
158+
$ cat >test.ml <<EOF
159+
> module type Example = [%import: (module type of A)]
160+
> EOF
161+
162+
$ dune build
163+
File "test.ml", line 1, characters 40-44:
164+
1 | module type Example = [%import: (module type of A)]
165+
^^^^
166+
Error: Syntax error
167+
[1]
168+
169+
Pmty_extension
170+
$ cat >test.ml <<EOF
171+
> module type M = [%import: [%extension]]
172+
> EOF
173+
174+
$ dune build
175+
File "test.ml", line 1, characters 26-38:
176+
1 | module type M = [%import: [%extension]]
177+
^^^^^^^^^^^^
178+
Error: package expected
179+
[1]
180+
181+
Pwith_module
182+
$ cat >test.ml <<EOF
183+
> module type StringHashable = sig
184+
> type t = string
185+
> val equal : t -> t -> bool
186+
> val hash : t -> int
187+
> end
188+
>
189+
> module StringHashable = struct
190+
> type t = string
191+
> let equal = (=)
192+
> let hash = Hashtbl.hash
193+
> end
194+
>
195+
> module type HashableWith = [%import: (module sig
196+
> include module type of StringHashable
197+
> end with module StringHashable = StringHashable)]
198+
> EOF
199+
200+
$ dune build
201+
File "test.ml", lines 13-15, characters 45-47:
202+
13 | .............................................sig
203+
14 | include module type of StringHashable
204+
15 | end with module StringHashable = StringHashable..
205+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
206+
[1]
207+
208+
Pwith_modtype
209+
$ cat >test.ml <<EOF
210+
> module type StringHashable = sig
211+
> type t = string
212+
> val equal : t -> t -> bool
213+
> val hash : t -> int
214+
> end
215+
>
216+
> module StringHashable = struct
217+
> type t = string
218+
> let equal = (=)
219+
> let hash = Hashtbl.hash
220+
> end
221+
>
222+
> module type HashableWith = [%import: (module sig
223+
> include module type of StringHashable
224+
> end with module type StringHashable = StringHashable)]
225+
> EOF
226+
227+
$ dune build
228+
File "test.ml", lines 13-15, characters 45-52:
229+
13 | .............................................sig
230+
14 | include module type of StringHashable
231+
15 | end with module type StringHashable = StringHashable..
232+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
233+
[1]
234+
235+
Pwith_typesubst
236+
$ cat >test.ml <<EOF
237+
> module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)]
238+
> EOF
239+
240+
$ dune build
241+
File "test.ml", line 1, characters 45-85:
242+
1 | module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)]
243+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
244+
Error: invalid package type: only 'with type t =' constraints are supported
245+
[1]
246+
247+
Pwith_modtypesubst
248+
$ cat >test.ml <<EOF
249+
> module type StringHashable = sig
250+
> type t = string
251+
> val equal : t -> t -> bool
252+
> val hash : t -> int
253+
> end
254+
>
255+
> module StringHashable = struct
256+
> type t = string
257+
> let equal = (=)
258+
> let hash = Hashtbl.hash
259+
> end
260+
>
261+
> module type HashableWith = [%import: (module sig
262+
> include module type of StringHashable
263+
> end with module type StringHashable := StringHashable)]
264+
> EOF
265+
266+
$ dune build
267+
File "test.ml", lines 13-15, characters 45-53:
268+
13 | .............................................sig
269+
14 | include module type of StringHashable
270+
15 | end with module type StringHashable := StringHashable..
271+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
272+
[1]
273+
274+
Pwith_modsubst
275+
$ cat >test.ml <<EOF
276+
> module type StringHashable = sig
277+
> type t = string
278+
> val equal : t -> t -> bool
279+
> val hash : t -> int
280+
> end
281+
>
282+
> module StringHashable = struct
283+
> type t = string
284+
> let equal = (=)
285+
> let hash = Hashtbl.hash
286+
> end
287+
>
288+
> module type HashableWith = [%import: (module sig
289+
> include module type of StringHashable
290+
> end with module StringHashable := StringHashable)]
291+
> EOF
292+
293+
$ dune build
294+
File "test.ml", lines 13-15, characters 45-48:
295+
13 | .............................................sig
296+
14 | include module type of StringHashable
297+
15 | end with module StringHashable := StringHashable..
298+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
299+
[1]

src_test/ppx_deriving/errors_lte_407/run.t

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,183 @@ Multiple signature items
9898
File "test.ml", line 1, characters 0-40:
9999
Error: [] expected
100100
[1]
101+
102+
Ptyp
103+
$ cat >test.ml <<EOF
104+
> [%%import: string]
105+
> EOF
106+
107+
$ dune build
108+
File "test.ml", line 1, characters 0-18:
109+
1 | [%%import: string]
110+
^^^^^^^^^^^^^^^^^^
111+
Error: PSig expected
112+
[1]
113+
114+
Inline module type declaration
115+
$ cat >test.ml <<EOF
116+
> module type Hashable = [%import: (module sig type t end)]
117+
> EOF
118+
119+
$ dune build
120+
File "test.ml", line 1, characters 41-55:
121+
1 | module type Hashable = [%import: (module sig type t end)]
122+
^^^^^^^^^^^^^^
123+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
124+
[1]
125+
126+
Functor
127+
$ cat >test.ml <<EOF
128+
> module type Foo = [%import: (module functor (M : sig end) -> sig end)]
129+
> EOF
130+
131+
$ dune build
132+
File "test.ml", line 1, characters 44-68:
133+
1 | module type Foo = [%import: (module functor (M : sig end) -> sig end)]
134+
^^^^^^^^^^^^^^^^^^^^^^^^
135+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
136+
[1]
137+
138+
Module type of
139+
$ cat >test.ml <<EOF
140+
> module type Example = [%import: (module type of A)]
141+
> EOF
142+
143+
$ dune build
144+
File "test.ml", line 1, characters 40-44:
145+
1 | module type Example = [%import: (module type of A)]
146+
^^^^
147+
Error: Syntax error
148+
[1]
149+
150+
Pmty_extension
151+
$ cat >test.ml <<EOF
152+
> module type M = [%import: [%extension]]
153+
> EOF
154+
155+
$ dune build
156+
File "test.ml", line 1, characters 26-38:
157+
1 | module type M = [%import: [%extension]]
158+
^^^^^^^^^^^^
159+
Error: package expected
160+
[1]
161+
162+
Pwith_module
163+
$ cat >test.ml <<EOF
164+
> module type StringHashable = sig
165+
> type t = string
166+
> val equal : t -> t -> bool
167+
> val hash : t -> int
168+
> end
169+
>
170+
> module StringHashable = struct
171+
> type t = string
172+
> let equal = (=)
173+
> let hash = Hashtbl.hash
174+
> end
175+
>
176+
> module type HashableWith = [%import: (module sig
177+
> include module type of StringHashable
178+
> end with module StringHashable = StringHashable)]
179+
> EOF
180+
181+
$ dune build
182+
File "test.ml", lines 13-15, characters 45-47:
183+
13 | .............................................sig
184+
14 | include module type of StringHashable
185+
15 | end with module StringHashable = StringHashable..
186+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
187+
[1]
188+
189+
Pwith_modtype
190+
$ cat >test.ml <<EOF
191+
> module type StringHashable = sig
192+
> type t = string
193+
> val equal : t -> t -> bool
194+
> val hash : t -> int
195+
> end
196+
>
197+
> module StringHashable = struct
198+
> type t = string
199+
> let equal = (=)
200+
> let hash = Hashtbl.hash
201+
> end
202+
>
203+
> module type HashableWith = [%import: (module sig
204+
> include module type of StringHashable
205+
> end with module type StringHashable = StringHashable)]
206+
> EOF
207+
208+
$ dune build
209+
File "test.ml", lines 13-15, characters 45-52:
210+
13 | .............................................sig
211+
14 | include module type of StringHashable
212+
15 | end with module type StringHashable = StringHashable..
213+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
214+
[1]
215+
216+
Pwith_typesubst
217+
$ cat >test.ml <<EOF
218+
> module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)]
219+
> EOF
220+
221+
$ dune build
222+
File "test.ml", line 1, characters 45-85:
223+
1 | module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)]
224+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
225+
Error: invalid package type: only 'with type t =' constraints are supported
226+
[1]
227+
228+
Pwith_modtypesubst
229+
$ cat >test.ml <<EOF
230+
> module type StringHashable = sig
231+
> type t = string
232+
> val equal : t -> t -> bool
233+
> val hash : t -> int
234+
> end
235+
>
236+
> module StringHashable = struct
237+
> type t = string
238+
> let equal = (=)
239+
> let hash = Hashtbl.hash
240+
> end
241+
>
242+
> module type HashableWith = [%import: (module sig
243+
> include module type of StringHashable
244+
> end with module type StringHashable := StringHashable)]
245+
> EOF
246+
247+
$ dune build
248+
File "test.ml", lines 13-15, characters 45-53:
249+
13 | .............................................sig
250+
14 | include module type of StringHashable
251+
15 | end with module type StringHashable := StringHashable..
252+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
253+
[1]
254+
255+
Pwith_modsubst
256+
$ cat >test.ml <<EOF
257+
> module type StringHashable = sig
258+
> type t = string
259+
> val equal : t -> t -> bool
260+
> val hash : t -> int
261+
> end
262+
>
263+
> module StringHashable = struct
264+
> type t = string
265+
> let equal = (=)
266+
> let hash = Hashtbl.hash
267+
> end
268+
>
269+
> module type HashableWith = [%import: (module sig
270+
> include module type of StringHashable
271+
> end with module StringHashable := StringHashable)]
272+
> EOF
273+
274+
$ dune build
275+
File "test.ml", lines 13-15, characters 45-48:
276+
13 | .............................................sig
277+
14 | include module type of StringHashable
278+
15 | end with module StringHashable := StringHashable..
279+
Error: invalid package type: only module type identifier and 'with type' constraints are supported
280+
[1]

0 commit comments

Comments
 (0)