Added new tests for type mismatch errors

master
Mekhrubon Turaev 2019-07-22 12:18:47 +01:00
parent 6cb5905c27
commit 0569b396ec
4 changed files with 301 additions and 0 deletions

View File

@ -0,0 +1,40 @@
(* TEST
* expect
*)
type t = ..;;
module M : sig type t += E | F end = struct type t += E | F of int end;;
[%%expect{|
type t = ..
Line 3, characters 37-70:
3 | module M : sig type t += E | F end = struct type t += E | F of int end;;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Signature mismatch:
Modules do not match:
sig type t += E | F of int end
is not included in
sig type t += E | F end
Extension declarations do not match:
type t += F of int
is not included in
type t += F
The arities for field F differ.
|}];;
module M1 : sig type t += A end = struct type t += private A end;;
[%%expect{|
Line 1, characters 34-64:
1 | module M1 : sig type t += A end = struct type t += private A end;;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Signature mismatch:
Modules do not match:
sig type t += private A end
is not included in
sig type t += A end
Extension declarations do not match:
type t += private A
is not included in
type t += A
A private type would be revealed.
|}];;

View File

@ -19,3 +19,6 @@ printing.ml
recursive.ml
Test.ml
unroll_private_abbrev.ml
records_errors_test.ml
variants_errors_test.ml
extension_constructors_errors_test.ml

View File

@ -0,0 +1,130 @@
(* TEST
* expect
*)
module M1 : sig
type t = {f0 : unit * unit * unit * int * unit * unit * unit;
f1 : unit * unit * unit * int * unit * unit * unit}
end = struct
type t = {f0 : unit * unit * unit * float* unit * unit * unit;
f1 : unit * unit * unit * string * unit * unit * unit}
end;;
[%%expect{|
Lines 4-7, characters 6-3:
4 | ......struct
5 | type t = {f0 : unit * unit * unit * float* unit * unit * unit;
6 | f1 : unit * unit * unit * string * unit * unit * unit}
7 | end..
Error: Signature mismatch:
Modules do not match:
sig
type t = {
f0 : unit * unit * unit * float * unit * unit * unit;
f1 : unit * unit * unit * string * unit * unit * unit;
}
end
is not included in
sig
type t = {
f0 : unit * unit * unit * int * unit * unit * unit;
f1 : unit * unit * unit * int * unit * unit * unit;
}
end
Type declarations do not match:
type t = {
f0 : unit * unit * unit * float * unit * unit * unit;
f1 : unit * unit * unit * string * unit * unit * unit;
}
is not included in
type t = {
f0 : unit * unit * unit * int * unit * unit * unit;
f1 : unit * unit * unit * int * unit * unit * unit;
}
The types for field f0 are not equal.
|}];;
module M2 : sig
type t = {mutable f0 : unit * unit * unit * int * unit * unit * unit;
f1 : unit * unit * unit * int * unit * unit * unit}
end = struct
type t = {f0 : unit * unit * unit * float* unit * unit * unit;
f1 : unit * unit * unit * string * unit * unit * unit}
end;;
[%%expect{|
Lines 4-7, characters 6-3:
4 | ......struct
5 | type t = {f0 : unit * unit * unit * float* unit * unit * unit;
6 | f1 : unit * unit * unit * string * unit * unit * unit}
7 | end..
Error: Signature mismatch:
Modules do not match:
sig
type t = {
f0 : unit * unit * unit * float * unit * unit * unit;
f1 : unit * unit * unit * string * unit * unit * unit;
}
end
is not included in
sig
type t = {
mutable f0 : unit * unit * unit * int * unit * unit * unit;
f1 : unit * unit * unit * int * unit * unit * unit;
}
end
Type declarations do not match:
type t = {
f0 : unit * unit * unit * float * unit * unit * unit;
f1 : unit * unit * unit * string * unit * unit * unit;
}
is not included in
type t = {
mutable f0 : unit * unit * unit * int * unit * unit * unit;
f1 : unit * unit * unit * int * unit * unit * unit;
}
The mutability of field f0 is different.
|}];;
module M3 : sig
type t = {f0 : unit}
end = struct
type t = {f1 : unit}
end;;
[%%expect{|
Lines 3-5, characters 6-3:
3 | ......struct
4 | type t = {f1 : unit}
5 | end..
Error: Signature mismatch:
Modules do not match:
sig type t = { f1 : unit; } end
is not included in
sig type t = { f0 : unit; } end
Type declarations do not match:
type t = { f1 : unit; }
is not included in
type t = { f0 : unit; }
Fields number 1 have different names, f1 and f0.
|}];;
module M4 : sig
type t = {f0 : unit; f1 : unit}
end = struct
type t = {f0 : unit}
end;;
[%%expect{|
Lines 3-5, characters 6-3:
3 | ......struct
4 | type t = {f0 : unit}
5 | end..
Error: Signature mismatch:
Modules do not match:
sig type t = { f0 : unit; } end
is not included in
sig type t = { f0 : unit; f1 : unit; } end
Type declarations do not match:
type t = { f0 : unit; }
is not included in
type t = { f0 : unit; f1 : unit; }
The field f1 is only present in the second declaration.
|}];;

View File

@ -0,0 +1,128 @@
(* TEST
* expect
*)
module M1 : sig
type t =
| Foo of int * int
end = struct
type t =
| Foo of float * int
end;;
[%%expect{|
Lines 4-7, characters 6-3:
4 | ......struct
5 | type t =
6 | | Foo of float * int
7 | end..
Error: Signature mismatch:
Modules do not match:
sig type t = Foo of float * int end
is not included in
sig type t = Foo of int * int end
Type declarations do not match:
type t = Foo of float * int
is not included in
type t = Foo of int * int
The types for field Foo are not equal.
|}];;
module M2 : sig
type t =
| Foo of int * int
end = struct
type t =
| Foo of float
end;;
[%%expect{|
Lines 4-7, characters 6-3:
4 | ......struct
5 | type t =
6 | | Foo of float
7 | end..
Error: Signature mismatch:
Modules do not match:
sig type t = Foo of float end
is not included in
sig type t = Foo of int * int end
Type declarations do not match:
type t = Foo of float
is not included in
type t = Foo of int * int
The arities for field Foo differ.
|}];;
module M3 : sig
type t =
| Foo of {x : int; y : int}
end = struct
type t =
| Foo of {x : float; y : int}
end;;
[%%expect{|
Lines 4-7, characters 6-3:
4 | ......struct
5 | type t =
6 | | Foo of {x : float; y : int}
7 | end..
Error: Signature mismatch:
Modules do not match:
sig type t = Foo of { x : float; y : int; } end
is not included in
sig type t = Foo of { x : int; y : int; } end
Type declarations do not match:
type t = Foo of { x : float; y : int; }
is not included in
type t = Foo of { x : int; y : int; }
The types for field x are not equal.
|}];;
module M4 : sig
type t =
| Foo of {x : int; y : int}
end = struct
type t =
| Foo of float
end;;
[%%expect{|
Lines 4-7, characters 6-3:
4 | ......struct
5 | type t =
6 | | Foo of float
7 | end..
Error: Signature mismatch:
Modules do not match:
sig type t = Foo of float end
is not included in
sig type t = Foo of { x : int; y : int; } end
Type declarations do not match:
type t = Foo of float
is not included in
type t = Foo of { x : int; y : int; }
The types for field Foo are not equal.
|}];;
module M5 : sig
type 'a t =
| Foo : int -> int t
end = struct
type 'a t =
| Foo of 'a
end;;
[%%expect{|
Lines 4-7, characters 6-3:
4 | ......struct
5 | type 'a t =
6 | | Foo of 'a
7 | end..
Error: Signature mismatch:
Modules do not match:
sig type 'a t = Foo of 'a end
is not included in
sig type 'a t = Foo : int -> int t end
Type declarations do not match:
type 'a t = Foo of 'a
is not included in
type 'a t = Foo : int -> int t
The types for field Foo are not equal.
|}];;