Skip to content

Commit

Permalink
add more module type error cases
Browse files Browse the repository at this point in the history
<!-- ps-id: d73095c3-be81-4a9c-8ad0-fddf33272dd4 -->
  • Loading branch information
tatchi committed Feb 20, 2023
1 parent fceb670 commit 1e5d960
Show file tree
Hide file tree
Showing 2 changed files with 360 additions and 0 deletions.
180 changes: 180 additions & 0 deletions src_test/ppx_deriving/errors/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,183 @@ It's been fixed for later versions in https://github.com/ocaml/ocaml/pull/8541
2 | type b = int
3 | type a = string]
Error: [] expected

Ptyp
$ cat >test.ml <<EOF
> [%%import: string]
> EOF

$ dune build
File "test.ml", line 1, characters 0-18:
1 | [%%import: string]
^^^^^^^^^^^^^^^^^^
Error: PSig expected
[1]

Inline module type declaration
$ cat >test.ml <<EOF
> module type Hashable = [%import: (module sig type t end)]
> EOF

$ dune build
File "test.ml", line 1, characters 41-55:
1 | module type Hashable = [%import: (module sig type t end)]
^^^^^^^^^^^^^^
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]

Functor
$ cat >test.ml <<EOF
> module type Foo = [%import: (module functor (M : sig end) -> sig end)]
> EOF

$ dune build
File "test.ml", line 1, characters 44-68:
1 | module type Foo = [%import: (module functor (M : sig end) -> sig end)]
^^^^^^^^^^^^^^^^^^^^^^^^
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]

Module type of
$ cat >test.ml <<EOF
> module type Example = [%import: (module type of A)]
> EOF

$ dune build
File "test.ml", line 1, characters 40-44:
1 | module type Example = [%import: (module type of A)]
^^^^
Error: Syntax error
[1]

Pmty_extension
$ cat >test.ml <<EOF
> module type M = [%import: [%extension]]
> EOF

$ dune build
File "test.ml", line 1, characters 26-38:
1 | module type M = [%import: [%extension]]
^^^^^^^^^^^^
Error: package expected
[1]

Pwith_module
$ cat >test.ml <<EOF
> module type StringHashable = sig
> type t = string
> val equal : t -> t -> bool
> val hash : t -> int
> end
>
> module StringHashable = struct
> type t = string
> let equal = (=)
> let hash = Hashtbl.hash
> end
>
> module type HashableWith = [%import: (module sig
> include module type of StringHashable
> end with module StringHashable = StringHashable)]
> EOF

$ dune build
File "test.ml", lines 13-15, characters 45-47:
13 | .............................................sig
14 | include module type of StringHashable
15 | end with module StringHashable = StringHashable..
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]

Pwith_modtype
$ cat >test.ml <<EOF
> module type StringHashable = sig
> type t = string
> val equal : t -> t -> bool
> val hash : t -> int
> end
>
> module StringHashable = struct
> type t = string
> let equal = (=)
> let hash = Hashtbl.hash
> end
>
> module type HashableWith = [%import: (module sig
> include module type of StringHashable
> end with module type StringHashable = StringHashable)]
> EOF

$ dune build
File "test.ml", lines 13-15, characters 45-52:
13 | .............................................sig
14 | include module type of StringHashable
15 | end with module type StringHashable = StringHashable..
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]

Pwith_typesubst
$ cat >test.ml <<EOF
> module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)]
> EOF

$ dune build
File "test.ml", line 1, characters 45-85:
1 | module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: invalid package type: only 'with type t =' constraints are supported
[1]
Pwith_modtypesubst
$ cat >test.ml <<EOF
> module type StringHashable = sig
> type t = string
> val equal : t -> t -> bool
> val hash : t -> int
> end
>
> module StringHashable = struct
> type t = string
> let equal = (=)
> let hash = Hashtbl.hash
> end
>
> module type HashableWith = [%import: (module sig
> include module type of StringHashable
> end with module type StringHashable := StringHashable)]
> EOF
$ dune build
File "test.ml", lines 13-15, characters 45-53:
13 | .............................................sig
14 | include module type of StringHashable
15 | end with module type StringHashable := StringHashable..
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]

Pwith_modsubst
$ cat >test.ml <<EOF
> module type StringHashable = sig
> type t = string
> val equal : t -> t -> bool
> val hash : t -> int
> end
>
> module StringHashable = struct
> type t = string
> let equal = (=)
> let hash = Hashtbl.hash
> end
>
> module type HashableWith = [%import: (module sig
> include module type of StringHashable
> end with module StringHashable := StringHashable)]
> EOF

$ dune build
File "test.ml", lines 13-15, characters 45-48:
13 | .............................................sig
14 | include module type of StringHashable
15 | end with module StringHashable := StringHashable..
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]
180 changes: 180 additions & 0 deletions src_test/ppx_deriving/errors_lte_407/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,183 @@ Multiple signature items
File "test.ml", line 1, characters 0-40:
Error: [] expected
[1]

Ptyp
$ cat >test.ml <<EOF
> [%%import: string]
> EOF

$ dune build
File "test.ml", line 1, characters 0-18:
1 | [%%import: string]
^^^^^^^^^^^^^^^^^^
Error: PSig expected
[1]

Inline module type declaration
$ cat >test.ml <<EOF
> module type Hashable = [%import: (module sig type t end)]
> EOF

$ dune build
File "test.ml", line 1, characters 41-55:
1 | module type Hashable = [%import: (module sig type t end)]
^^^^^^^^^^^^^^
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]

Functor
$ cat >test.ml <<EOF
> module type Foo = [%import: (module functor (M : sig end) -> sig end)]
> EOF

$ dune build
File "test.ml", line 1, characters 44-68:
1 | module type Foo = [%import: (module functor (M : sig end) -> sig end)]
^^^^^^^^^^^^^^^^^^^^^^^^
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]

Module type of
$ cat >test.ml <<EOF
> module type Example = [%import: (module type of A)]
> EOF

$ dune build
File "test.ml", line 1, characters 40-44:
1 | module type Example = [%import: (module type of A)]
^^^^
Error: Syntax error
[1]

Pmty_extension
$ cat >test.ml <<EOF
> module type M = [%import: [%extension]]
> EOF

$ dune build
File "test.ml", line 1, characters 26-38:
1 | module type M = [%import: [%extension]]
^^^^^^^^^^^^
Error: package expected
[1]

Pwith_module
$ cat >test.ml <<EOF
> module type StringHashable = sig
> type t = string
> val equal : t -> t -> bool
> val hash : t -> int
> end
>
> module StringHashable = struct
> type t = string
> let equal = (=)
> let hash = Hashtbl.hash
> end
>
> module type HashableWith = [%import: (module sig
> include module type of StringHashable
> end with module StringHashable = StringHashable)]
> EOF

$ dune build
File "test.ml", lines 13-15, characters 45-47:
13 | .............................................sig
14 | include module type of StringHashable
15 | end with module StringHashable = StringHashable..
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]

Pwith_modtype
$ cat >test.ml <<EOF
> module type StringHashable = sig
> type t = string
> val equal : t -> t -> bool
> val hash : t -> int
> end
>
> module StringHashable = struct
> type t = string
> let equal = (=)
> let hash = Hashtbl.hash
> end
>
> module type HashableWith = [%import: (module sig
> include module type of StringHashable
> end with module type StringHashable = StringHashable)]
> EOF

$ dune build
File "test.ml", lines 13-15, characters 45-52:
13 | .............................................sig
14 | include module type of StringHashable
15 | end with module type StringHashable = StringHashable..
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]

Pwith_typesubst
$ cat >test.ml <<EOF
> module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)]
> EOF

$ dune build
File "test.ml", line 1, characters 45-85:
1 | module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: invalid package type: only 'with type t =' constraints are supported
[1]
Pwith_modtypesubst
$ cat >test.ml <<EOF
> module type StringHashable = sig
> type t = string
> val equal : t -> t -> bool
> val hash : t -> int
> end
>
> module StringHashable = struct
> type t = string
> let equal = (=)
> let hash = Hashtbl.hash
> end
>
> module type HashableWith = [%import: (module sig
> include module type of StringHashable
> end with module type StringHashable := StringHashable)]
> EOF
$ dune build
File "test.ml", lines 13-15, characters 45-53:
13 | .............................................sig
14 | include module type of StringHashable
15 | end with module type StringHashable := StringHashable..
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]

Pwith_modsubst
$ cat >test.ml <<EOF
> module type StringHashable = sig
> type t = string
> val equal : t -> t -> bool
> val hash : t -> int
> end
>
> module StringHashable = struct
> type t = string
> let equal = (=)
> let hash = Hashtbl.hash
> end
>
> module type HashableWith = [%import: (module sig
> include module type of StringHashable
> end with module StringHashable := StringHashable)]
> EOF

$ dune build
File "test.ml", lines 13-15, characters 45-48:
13 | .............................................sig
14 | include module type of StringHashable
15 | end with module StringHashable := StringHashable..
Error: invalid package type: only module type identifier and 'with type' constraints are supported
[1]

0 comments on commit 1e5d960

Please sign in to comment.