Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abbreviate module types when printing error messages #1895

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
(* TEST
* expect
*)

module Width = struct
module type S1 = sig
val a : int
val b : int
val c : int
val d : int
val e : int
end


module type F = functor
(X :
sig
module M1 : sig include S1 end
module M2 : sig include S1 end
module M3 : sig include S1 end
module M4 : sig include S1 end
module M5 : sig include S1 end
module M6 : sig include S1 end
module M7 : sig include S1 end
end
) -> S1

module G(F:F)(X:functor() -> S1) = F(X)
end

[%%expect{|
Line 24, characters 37-41:
24 | module G(F:F)(X:functor() -> S1) = F(X)
^^^^
Error: Modules do not match: functor () -> S1 is not included in
sig
module M1 :
sig
val a : int
val b : int
val c : int
val d : int
val e : int
end
module M2 :
sig val a : int val b : int val c : int val d : int ... end
module M3 : sig ... end
module M4 : sig ... end
module M5 : sig ... end
module M6 : sig ... end
module M7 : sig ... end
end
Modules do not match:
functor () -> ...
is not included in
functor -> ...
An extra argument is provided of module type ()
|}]

module Depth = struct
module type S = sig
module M : sig
module N : sig
module O : sig
module P : sig
module Q : sig
val x : int
val y : int
end
end
end
end
end
end

module type F = functor(X:S) -> S

module F(F : F)(X : sig module M : sig end end) = F(X)
end

[%%expect{|
Line 19, characters 52-56:
19 | module F(F : F)(X : sig module M : sig end end) = F(X)
^^^^
Error: Modules do not match: sig module M : sig end end is not included in
S
In module M:
Modules do not match:
sig end
is not included in
sig
module N :
sig
module O : sig module P : sig module Q : sig ... end end end
end
end
In module M: The module `N' is required but not provided
|}]
31 changes: 4 additions & 27 deletions ocaml/testsuite/tests/typing-modules/functors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -921,37 +921,14 @@ Error: Signature mismatch:
sig
module B :
sig
module C :
sig
module D :
sig
module E :
sig
module F :
functor (X : sig type x end)
(Y : sig type y' end) (W : sig type w end) ->
sig end
end
end
end
module C : sig module D : sig module E : sig ... end end end
end
end
is not included in
sig
module B :
sig
module C :
sig
module D :
sig
module E :
sig
module F :
sig type x end -> sig type y end ->
sig type z end -> sig type w end -> sig end
end
end
end
module C : sig module D : sig module E : sig ... end end end
end
end
In module B:
Expand All @@ -966,8 +943,8 @@ Error: Signature mismatch:
module E :
sig
module F :
sig type x end -> sig type y end ->
sig type z end -> sig type w end -> sig end
sig ... end -> sig ... end -> sig ... end ->
goldfirere marked this conversation as resolved.
Show resolved Hide resolved
sig ... end -> sig end
end
end
end
Expand Down
68 changes: 4 additions & 64 deletions ocaml/testsuite/tests/typing-modules/illegal_permutation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -502,22 +502,7 @@ Error: Signature mismatch:
sig
module C :
functor (X : sig end) (Y : sig end)
(Z : sig
module D :
sig
module E :
sig
module F :
functor (X : sig end)
(Arg : sig
val two : int
val one : int
end)
-> sig end
end
end
end)
-> sig end
(Z : sig ... end) -> sig end
goldfirere marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
Expand All @@ -532,22 +517,7 @@ Error: Signature mismatch:
sig
module C :
functor (X : sig end) (Y : sig end)
(Z : sig
module D :
sig
module E :
sig
module F :
functor (X : sig end)
(Arg : sig
val one : int
val two : int
end)
-> sig end
end
end
end)
-> sig end
(Z : sig ... end) -> sig end
end
end
end
Expand All @@ -561,22 +531,7 @@ Error: Signature mismatch:
sig
module C :
functor (X : sig end) (Y : sig end)
(Z : sig
module D :
sig
module E :
sig
module F :
functor (X : sig end)
(Arg : sig
val two : int
val one : int
end)
-> sig end
end
end
end)
-> sig end
(Z : sig module D : sig ... end end) -> sig end
end
end
end
Expand All @@ -589,22 +544,7 @@ Error: Signature mismatch:
sig
module C :
functor (X : sig end) (Y : sig end)
(Z : sig
module D :
sig
module E :
sig
module F :
functor (X : sig end)
(Arg : sig
val one : int
val two : int
end)
-> sig end
end
end
end)
-> sig end
(Z : sig module D : sig ... end end) -> sig end
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions ocaml/typing/includemod_errorprinter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ let show_locs ppf (loc1, loc2) =


let dmodtype mty =
let tmty = Printtyp.tree_of_modtype mty in
let tmty = Printtyp.tree_of_modtype ~abbrev:true mty in
Format.dprintf "%a" !Oprint.out_module_type tmty

let space ppf () = Format.fprintf ppf "@ "
Expand Down Expand Up @@ -666,22 +666,22 @@ let module_types {Err.got=mty1; expected=mty2} =
Format.dprintf
"@[<hv 2>Modules do not match:@ \
%a@;<1 -2>is not included in@ %a@]"
!Oprint.out_module_type (Printtyp.tree_of_modtype mty1)
!Oprint.out_module_type (Printtyp.tree_of_modtype mty2)
!Oprint.out_module_type (Printtyp.tree_of_modtype ~abbrev:true mty1)
!Oprint.out_module_type (Printtyp.tree_of_modtype ~abbrev:true mty2)

let eq_module_types {Err.got=mty1; expected=mty2} =
Format.dprintf
"@[<hv 2>Module types do not match:@ \
%a@;<1 -2>is not equal to@ %a@]"
!Oprint.out_module_type (Printtyp.tree_of_modtype mty1)
!Oprint.out_module_type (Printtyp.tree_of_modtype mty2)
!Oprint.out_module_type (Printtyp.tree_of_modtype ~abbrev:true mty1)
!Oprint.out_module_type (Printtyp.tree_of_modtype ~abbrev:true mty2)

let module_type_declarations id {Err.got=d1 ; expected=d2} =
Format.dprintf
"@[<hv 2>Module type declarations do not match:@ \
%a@;<1 -2>does not match@ %a@]"
!Oprint.out_sig_item (Printtyp.tree_of_modtype_declaration id d1)
!Oprint.out_sig_item (Printtyp.tree_of_modtype_declaration id d2)
!Oprint.out_sig_item (Printtyp.tree_of_modtype_declaration ~abbrev:true id d1)
!Oprint.out_sig_item (Printtyp.tree_of_modtype_declaration ~abbrev:true id d2)

let interface_mismatch ppf (diff: _ Err.diff) =
Format.fprintf ppf
Expand Down
Loading
Loading