From 1e5d960509770739ca6701a3f95a107c44647bc6 Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Wed, 8 Feb 2023 18:35:44 +0100 Subject: [PATCH] add more module type error cases --- src_test/ppx_deriving/errors/run.t | 180 +++++++++++++++++++++ src_test/ppx_deriving/errors_lte_407/run.t | 180 +++++++++++++++++++++ 2 files changed, 360 insertions(+) diff --git a/src_test/ppx_deriving/errors/run.t b/src_test/ppx_deriving/errors/run.t index e05ef41..2578aec 100644 --- a/src_test/ppx_deriving/errors/run.t +++ b/src_test/ppx_deriving/errors/run.t @@ -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 < [%%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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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] diff --git a/src_test/ppx_deriving/errors_lte_407/run.t b/src_test/ppx_deriving/errors_lte_407/run.t index da8c997..5bd3a80 100644 --- a/src_test/ppx_deriving/errors_lte_407/run.t +++ b/src_test/ppx_deriving/errors_lte_407/run.t @@ -98,3 +98,183 @@ Multiple signature items File "test.ml", line 1, characters 0-40: Error: [] expected [1] + +Ptyp + $ cat >test.ml < [%%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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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]