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

Generate full error traces during module inclusion #10407

Merged
merged 10 commits into from
Jun 22, 2021
3 changes: 3 additions & 0 deletions .depend
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ typing/includeclass.cmx : \
typing/includeclass.cmi
typing/includeclass.cmi : \
typing/types.cmi \
typing/printtyp.cmi \
parsing/location.cmi \
typing/env.cmi \
typing/ctype.cmi
Expand All @@ -689,6 +690,7 @@ typing/includecore.cmo : \
typing/printtyp.cmi \
typing/primitive.cmi \
typing/path.cmi \
utils/misc.cmi \
typing/ident.cmi \
typing/errortrace.cmi \
typing/env.cmi \
Expand All @@ -704,6 +706,7 @@ typing/includecore.cmx : \
typing/printtyp.cmx \
typing/primitive.cmx \
typing/path.cmx \
utils/misc.cmx \
typing/ident.cmx \
typing/errortrace.cmx \
typing/env.cmx \
Expand Down
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Working version
- #10328: Give more precise error when disambiguation could not possibly work.
(Leo White, review by Gabriel Scherer and Florian Angeletti)

- #10407: Produce more detailed error messages that contain full error traces
when module inclusion fails.
(Antal Spector-Zabusky, review by Florian Angeletti)

### Internal/compiler-libs changes:

- #10433: Remove the distinction between 32-bit aligned and 64-bit aligned
Expand Down
6 changes: 4 additions & 2 deletions testsuite/tests/printing-types/disambiguation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ Error: Type declarations do not match:
type !'a x = private [> `x ] constraint 'a = 'a x
is not included in
type 'a x
Their constraints differ.
Their parameters differ
The type 'b x as 'b is not equal to the type 'a
|}, Principal{|
Line 1:
Error: Type declarations do not match:
type !'a x = private 'a constraint 'a = [> `x ]
is not included in
type 'a x
Their constraints differ.
Their parameters differ
The type [> `x ] is not equal to the type 'a
|}];;


Expand Down
16 changes: 8 additions & 8 deletions testsuite/tests/typing-extensions/extensions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ Error: Signature mismatch:
type ('a, 'b) bar += A of int
Constructors do not match:
A of float
is not compatible with:
is not the same as:
A of int
The types are not equal.
The type float is not equal to the type int
|}]

module M : sig
Expand All @@ -348,9 +348,9 @@ Error: Signature mismatch:
type ('a, 'b) bar += A of 'a
Constructors do not match:
A of 'b
is not compatible with:
is not the same as:
A of 'a
The types are not equal.
The type 'b is not equal to the type 'a
|}]

module M : sig
Expand All @@ -374,9 +374,9 @@ Error: Signature mismatch:
type ('a, 'b) bar = A of 'a
Constructors do not match:
A of 'a
is not compatible with:
is not the same as:
A of 'a
The types are not equal.
The type 'a is not equal to the type 'b
|}];;


Expand All @@ -401,9 +401,9 @@ Error: Signature mismatch:
type ('a, 'b) bar += A : 'c -> ('c, 'd) bar
Constructors do not match:
A : 'd -> ('c, 'd) bar
is not compatible with:
is not the same as:
A : 'c -> ('c, 'd) bar
The types are not equal.
The type 'd is not equal to the type 'c
|}]

(* Extensions can be rebound *)
Expand Down
5 changes: 3 additions & 2 deletions testsuite/tests/typing-extensions/open_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ Line 1, characters 0-37:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This variant or record definition does not match that of type
('a, 'a) foo
Their constraints differ.
Their parameters differ
The type 'a is not equal to the type 'b
|}]

(* Check that signatures can hide exstensibility *)
Expand Down Expand Up @@ -236,7 +237,7 @@ Error: Signature mismatch:
type foo = M.foo = private ..
is not included in
type foo = ..
A private type would be revealed.
A private extensible variant would be revealed.
|}]


Expand Down
8 changes: 8 additions & 0 deletions testsuite/tests/typing-gadts/ambiguity.ml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ Error: Signature mismatch:
val r : '_weak1 list ref
is not included in
val r : T.u list ref
The type '_weak1 list ref is not compatible with the type T.u list ref
Type '_weak1 is not compatible with type T.u = T.t
This instance of T.t is ambiguous:
it would escape the scope of its equation
|}]

module M = struct
Expand Down Expand Up @@ -264,4 +268,8 @@ Error: Signature mismatch:
val r : '_weak2 list ref
is not included in
val r : T.t list ref
The type '_weak2 list ref is not compatible with the type T.t list ref
Type '_weak2 is not compatible with type T.t = T.u
This instance of T.u is ambiguous:
it would escape the scope of its equation
|}]
5 changes: 3 additions & 2 deletions testsuite/tests/typing-gadts/pr7160.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Lines 4-5, characters 0-77:
Error: This variant or record definition does not match that of type 'a t
Constructors do not match:
Same : 'l t -> 'l t
is not compatible with:
is not the same as:
Same : 'l1 t -> 'l2 t
The types are not equal.
The type 'l t is not equal to the type 'l1 t
Type 'l is not equal to type 'l1
|}];;
5 changes: 3 additions & 2 deletions testsuite/tests/typing-gadts/pr7378.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ Lines 2-3, characters 2-37:
Error: This variant or record definition does not match that of type X.t
Constructors do not match:
A : 'a * 'b * ('a -> unit) -> X.t
is not compatible with:
is not the same as:
A : 'a * 'b * ('b -> unit) -> X.t
The types are not equal.
The type 'a -> unit is not equal to the type 'b -> unit
Type 'a is not equal to type 'b
|}]

(* would segfault
Expand Down
36 changes: 36 additions & 0 deletions testsuite/tests/typing-gadts/return_type.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(* TEST
* expect
*)

type i = int

type 'a t = T : i
[%%expect{|
type i = int
Line 3, characters 16-17:
3 | type 'a t = T : i
^
Error: Constraints are not satisfied in this type.
Type i should be an instance of 'a t
|}]

type 'a t = T : i t
type 'a s = 'a t = T : i t
[%%expect{|
type 'a t = T : i t
Line 2, characters 23-26:
2 | type 'a s = 'a t = T : i t
^^^
Error: Constraints are not satisfied in this type.
Type i t should be an instance of 'a s
|}]

type 'a t = T : i s
and 'a s = 'a t
[%%expect{|
Line 1, characters 16-19:
1 | type 'a t = T : i s
^^^
Error: Constraints are not satisfied in this type.
Type i s should be an instance of 'a t
|}]
133 changes: 133 additions & 0 deletions testsuite/tests/typing-gadts/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1246,3 +1246,136 @@ Error: This expression has type a = int
This instance of int is ambiguous:
it would escape the scope of its equation
|}];;

module M = struct
type t
end
type (_,_) eq = Refl: ('a,'a) eq
let f (x:M.t) (y: (M.t, int -> int) eq) =
let Refl = y in
if true then x else fun x -> x + 1
[%%expect{|
module M : sig type t end
type (_, _) eq = Refl : ('a, 'a) eq
Line 7, characters 22-36:
7 | if true then x else fun x -> x + 1
^^^^^^^^^^^^^^
Error: This expression has type 'a -> 'b
but an expression was expected of type M.t = int -> int
This instance of int -> int is ambiguous:
it would escape the scope of its equation
|}]

(* Check got/expected when the order changes *)
module M = struct
type t
end
type (_,_) eq = Refl: ('a,'a) eq
let f (x:M.t) (y: (M.t, int -> int) eq) =
let Refl = y in
if true then fun x -> x + 1 else x
[%%expect{|
module M : sig type t end
type (_, _) eq = Refl : ('a, 'a) eq
Line 7, characters 35-36:
7 | if true then fun x -> x + 1 else x
^
Error: This expression has type M.t = int -> int
but an expression was expected of type int -> int
This instance of int -> int is ambiguous:
it would escape the scope of its equation
|}]

module M = struct
type t
end
type (_,_) eq = Refl: ('a,'a) eq
let f w (x:M.t) (y: (M.t, <m:int>) eq) =
let Refl = y in
let z = if true then x else w in
z#m
[%%expect{|
module M : sig type t end
type (_, _) eq = Refl : ('a, 'a) eq
Line 8, characters 2-3:
8 | z#m
^
Error: This expression has type M.t but an expression was expected of type
< m : 'a; .. >
This instance of < m : int > is ambiguous:
it would escape the scope of its equation
|}]

(* Check got/expected when the order changes *)
module M = struct
type t
end
type (_,_) eq = Refl: ('a,'a) eq
let f w (x:M.t) (y: (M.t, <m:int>) eq) =
let Refl = y in
let z = if true then w else x in
z#m
[%%expect{|
module M : sig type t end
type (_, _) eq = Refl : ('a, 'a) eq
Line 8, characters 2-3:
8 | z#m
^
Error: This expression has type M.t but an expression was expected of type
< m : 'a; .. >
This instance of < m : int > is ambiguous:
it would escape the scope of its equation
|}]

type (_,_) eq = Refl: ('a,'a) eq
module M = struct
type t = C : (<m:int; ..> as 'a) * ('a, <m:int; b:bool>) eq -> t
end
let f (C (x,y) : M.t) =
let g w =
let Refl = y in
let z = if true then w else x in
z#b
in ()
[%%expect{|
type (_, _) eq = Refl : ('a, 'a) eq
module M :
sig
type t =
C : (< m : int; .. > as 'a) * ('a, < b : bool; m : int >) eq -> t
end
Line 9, characters 4-5:
9 | z#b
^
Error: This expression has type $C_'a = < b : bool >
but an expression was expected of type < b : 'a; .. >
This instance of < b : bool > is ambiguous:
it would escape the scope of its equation
|}]

(* Check got/expected when the order changes *)
type (_,_) eq = Refl: ('a,'a) eq
module M = struct
type t = C : (<m:int; ..> as 'a) * ('a, <m:int; b:bool>) eq -> t
end
let f (C (x,y) : M.t) =
let g w =
let Refl = y in
let z = if true then x else w in
z#b
in ()
[%%expect{|
type (_, _) eq = Refl : ('a, 'a) eq
module M :
sig
type t =
C : (< m : int; .. > as 'a) * ('a, < b : bool; m : int >) eq -> t
end
Line 9, characters 4-5:
9 | z#b
^
Error: This expression has type $C_'a = < b : bool >
but an expression was expected of type < b : 'a; .. >
This instance of < b : bool > is ambiguous:
it would escape the scope of its equation
|}]