switch typing-misc and typing-modules to Makefile.expect

master
Jacques Garrigue 2016-06-13 14:09:23 +09:00
parent 80d24ec8b0
commit 87098044bb
49 changed files with 855 additions and 989 deletions

View File

@ -14,5 +14,5 @@
#**************************************************************************
BASEDIR=../..
include $(BASEDIR)/makefiles/Makefile.toplevel
include $(BASEDIR)/makefiles/Makefile.expect
include $(BASEDIR)/makefiles/Makefile.common

View File

@ -1,19 +1,53 @@
type 'a t = [`A of 'a t t] as 'a;; (* fails *)
[%%expect{|
Line _, characters 12-32:
Error: Constraints are not satisfied in this type.
Type
[ `A of 'a ] t t as 'a
should be an instance of
([ `A of 'b t t ] as 'b) t
|}, Principal{|
type 'a t = [ `A of 'b t t ] as 'b constraint 'a = [ `A of 'a t t ]
|}];;
type 'a t = [`A of 'a t t];; (* fails *)
[%%expect{|
Line _, characters 0-26:
Error: In the definition of t, type 'a t t should be 'a t
|}];;
type 'a t = [`A of 'a t t] constraint 'a = 'a t;;
[%%expect{|
type 'a t = [ `A of 'a t t ] constraint 'a = 'a t
|}];;
type 'a t = [`A of 'a t] constraint 'a = 'a t;;
[%%expect{|
type 'a t = [ `A of 'a t ] constraint 'a = 'a t
|}];;
type 'a t = [`A of 'a] as 'a;;
[%%expect{|
type 'a t = 'a constraint 'a = [ `A of 'a ]
|}, Principal{|
type 'a t = [ `A of 'b ] as 'b constraint 'a = [ `A of 'a ]
|}];;
type 'a v = [`A of u v] constraint 'a = t and t = u and u = t;; (* fails *)
[%%expect{|
Line _, characters 42-51:
Error: The type abbreviation t is cyclic
|}];;
type 'a t = 'a;;
let f (x : 'a t as 'a) = ();; (* fails *)
[%%expect{|
type 'a t = 'a
Line _, characters 11-21:
Error: This alias is bound to type 'a t = 'a
but is used as an instance of type 'a
The type variable 'a occurs inside 'a
|}];;
let f (x : 'a t) (y : 'a) = x = y;;
[%%expect{|
val f : 'a t -> 'a -> bool = <fun>
|}];;
(* PR#6505 *)
module type PR6505 = sig
@ -22,3 +56,16 @@ module type PR6505 = sig
val abs : 'o is_an_object -> 'o abs
val unabs : 'o abs -> 'o
end;; (* fails *)
[%%expect{|
Line _, characters 2-44:
Error: The definition of abs contains a cycle:
'a is_an_object as 'a
|}, Principal{|
module type PR6505 =
sig
type 'o is_an_object = 'o constraint 'o = < .. >
and 'a abs constraint 'a = 'a is_an_object
val abs : ('a is_an_object as 'a) is_an_object -> 'a abs
val unabs : ('a is_an_object as 'a) abs -> 'a
end
|}];;

View File

@ -1,34 +0,0 @@
# Characters 12-32:
type 'a t = [`A of 'a t t] as 'a;; (* fails *)
^^^^^^^^^^^^^^^^^^^^
Error: Constraints are not satisfied in this type.
Type
[ `A of 'a ] t t as 'a
should be an instance of
([ `A of 'b t t ] as 'b) t
# Characters 1-27:
type 'a t = [`A of 'a t t];; (* fails *)
^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: In the definition of t, type 'a t t should be 'a t
# type 'a t = [ `A of 'a t t ] constraint 'a = 'a t
# type 'a t = [ `A of 'a t ] constraint 'a = 'a t
# type 'a t = 'a constraint 'a = [ `A of 'a ]
# Characters 43-52:
type 'a v = [`A of u v] constraint 'a = t and t = u and u = t;; (* fails *)
^^^^^^^^^
Error: The type abbreviation t is cyclic
# type 'a t = 'a
# Characters 11-21:
let f (x : 'a t as 'a) = ();; (* fails *)
^^^^^^^^^^
Error: This alias is bound to type 'a t = 'a
but is used as an instance of type 'a
The type variable 'a occurs inside 'a
# val f : 'a t -> 'a -> bool = <fun>
# Characters 80-122:
and 'o abs constraint 'o = 'o is_an_object
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The definition of abs contains a cycle:
'a is_an_object as 'a
#

View File

@ -1,11 +1,27 @@
(* PR#5835 *)
let f ~x = x + 1;;
f ?x:0;;
[%%expect{|
val f : x:int -> int = <fun>
Line _, characters 5-6:
Warning 43: the label x is not optional.
- : int = 1
|}];;
(* PR#6352 *)
let foo (f : unit -> unit) = ();;
let g ?x () = ();;
foo ((); g);;
[%%expect{|
val foo : (unit -> unit) -> unit = <fun>
val g : ?x:'a -> unit -> unit = <fun>
- : unit = ()
|}];;
(* PR#5748 *)
foo (fun ?opt () -> ()) ;; (* fails *)
[%%expect{|
Line _, characters 4-23:
Error: This function should have type unit -> unit
but its first argument is labelled ?opt
|}];;

View File

@ -1,16 +0,0 @@
# val f : x:int -> int = <fun>
# Characters 5-6:
f ?x:0;;
^
Warning 43: the label x is not optional.
- : int = 1
# val foo : (unit -> unit) -> unit = <fun>
# val g : ?x:'a -> unit -> unit = <fun>
# - : unit = ()
# Characters 19-38:
foo (fun ?opt () -> ()) ;; (* fails *)
^^^^^^^^^^^^^^^^^^^
Error: This function should have type unit -> unit
but its first argument is labelled ?opt
#

View File

@ -1,16 +0,0 @@
# val f : x:int -> int = <fun>
# Characters 5-6:
f ?x:0;;
^
Warning 43: the label x is not optional.
- : int = 1
# val foo : (unit -> unit) -> unit = <fun>
# val g : ?x:'a -> unit -> unit = <fun>
# - : unit = ()
# Characters 19-38:
foo (fun ?opt () -> ()) ;; (* fails *)
^^^^^^^^^^^^^^^^^^^
Error: This function should have type unit -> unit
but its first argument is labelled ?opt
#

View File

@ -2,4 +2,17 @@
type 'a t = 'a;;
let f (g : 'a list -> 'a t -> 'a) s = g s s;;
[%%expect{|
type 'a t = 'a
Line _, characters 42-43:
Error: This expression has type 'a list
but an expression was expected of type 'a t = 'a
The type variable 'a occurs inside 'a list
|}];;
let f (g : 'a * 'b -> 'a t -> 'a) s = g s s;;
[%%expect{|
Line _, characters 42-43:
Error: This expression has type 'a * 'b
but an expression was expected of type 'a t = 'a
The type variable 'a occurs inside 'a * 'b
|}];;

View File

@ -1,15 +0,0 @@
# type 'a t = 'a
# Characters 42-43:
let f (g : 'a list -> 'a t -> 'a) s = g s s;;
^
Error: This expression has type 'a list
but an expression was expected of type 'a t = 'a
The type variable 'a occurs inside 'a list
# Characters 42-43:
let f (g : 'a * 'b -> 'a t -> 'a) s = g s s;;
^
Error: This expression has type 'a * 'b
but an expression was expected of type 'a t = 'a
The type variable 'a occurs inside 'a * 'b
#

View File

@ -1,10 +1,50 @@
type ab = [ `A | `B ];;
let f (x : [`A]) = match x with #ab -> 1;;
[%%expect{|
type ab = [ `A | `B ]
Line _, characters 32-35:
Error: This pattern matches values of type [? `A | `B ]
but a pattern was expected which matches values of type [ `A ]
The second variant type does not allow tag(s) `B
|}];;
let f x = ignore (match x with #ab -> 1); ignore (x : [`A]);;
[%%expect{|
Line _, characters 31-34:
Error: This pattern matches values of type [? `B ]
but a pattern was expected which matches values of type [ `A ]
The second variant type does not allow tag(s) `B
|}, Principal{|
Line _, characters 31-34:
Error: This pattern matches values of type [? `B ]
but a pattern was expected which matches values of type [ `A ]
Types for tag `B are incompatible
|}];;
let f x = ignore (match x with `A|`B -> 1); ignore (x : [`A]);;
[%%expect{|
Line _, characters 34-36:
Error: This pattern matches values of type [? `B ]
but a pattern was expected which matches values of type [ `A ]
The second variant type does not allow tag(s) `B
|}, Principal{|
Line _, characters 34-36:
Error: This pattern matches values of type [? `B ]
but a pattern was expected which matches values of type [ `A ]
Types for tag `B are incompatible
|}];;
let f (x : [< `A | `B]) = match x with `A | `B | `C -> 0;; (* warn *)
[%%expect{|
Line _, characters 49-51:
Warning 12: this sub-pattern is unused.
val f : [< `A | `B ] -> int = <fun>
|}];;
let f (x : [`A | `B]) = match x with `A | `B | `C -> 0;; (* fail *)
[%%expect{|
Line _, characters 47-49:
Error: This pattern matches values of type [? `C ]
but a pattern was expected which matches values of type [ `A | `B ]
The second variant type does not allow tag(s) `C
|}];;
(* PR#6787 *)
let revapply x f = f x;;
@ -13,3 +53,7 @@ let f x (g : [< `Foo]) =
let y = `Bar x, g in
revapply y (fun ((`Bar i), _) -> i);;
(* f : 'a -> [< `Foo ] -> 'a *)
[%%expect{|
val revapply : 'a -> ('a -> 'b) -> 'b = <fun>
val f : 'a -> [< `Foo ] -> 'a = <fun>
|}];;

View File

@ -1,34 +0,0 @@
# type ab = [ `A | `B ]
# Characters 32-35:
let f (x : [`A]) = match x with #ab -> 1;;
^^^
Error: This pattern matches values of type [? `A | `B ]
but a pattern was expected which matches values of type [ `A ]
The second variant type does not allow tag(s) `B
# Characters 31-34:
let f x = ignore (match x with #ab -> 1); ignore (x : [`A]);;
^^^
Error: This pattern matches values of type [? `B ]
but a pattern was expected which matches values of type [ `A ]
Types for tag `B are incompatible
# Characters 34-36:
let f x = ignore (match x with `A|`B -> 1); ignore (x : [`A]);;
^^
Error: This pattern matches values of type [? `B ]
but a pattern was expected which matches values of type [ `A ]
Types for tag `B are incompatible
# Characters 50-52:
let f (x : [< `A | `B]) = match x with `A | `B | `C -> 0;; (* warn *)
^^
Warning 12: this sub-pattern is unused.
val f : [< `A | `B ] -> int = <fun>
# Characters 47-49:
let f (x : [`A | `B]) = match x with `A | `B | `C -> 0;; (* fail *)
^^
Error: This pattern matches values of type [? `C ]
but a pattern was expected which matches values of type [ `A | `B ]
The second variant type does not allow tag(s) `C
# val revapply : 'a -> ('a -> 'b) -> 'b = <fun>
# val f : 'a -> [< `Foo ] -> 'a = <fun>
#

View File

@ -1,34 +0,0 @@
# type ab = [ `A | `B ]
# Characters 32-35:
let f (x : [`A]) = match x with #ab -> 1;;
^^^
Error: This pattern matches values of type [? `A | `B ]
but a pattern was expected which matches values of type [ `A ]
The second variant type does not allow tag(s) `B
# Characters 31-34:
let f x = ignore (match x with #ab -> 1); ignore (x : [`A]);;
^^^
Error: This pattern matches values of type [? `B ]
but a pattern was expected which matches values of type [ `A ]
The second variant type does not allow tag(s) `B
# Characters 34-36:
let f x = ignore (match x with `A|`B -> 1); ignore (x : [`A]);;
^^
Error: This pattern matches values of type [? `B ]
but a pattern was expected which matches values of type [ `A ]
The second variant type does not allow tag(s) `B
# Characters 50-52:
let f (x : [< `A | `B]) = match x with `A | `B | `C -> 0;; (* warn *)
^^
Warning 12: this sub-pattern is unused.
val f : [< `A | `B ] -> int = <fun>
# Characters 47-49:
let f (x : [`A | `B]) = match x with `A | `B | `C -> 0;; (* fail *)
^^
Error: This pattern matches values of type [? `C ]
but a pattern was expected which matches values of type [ `A | `B ]
The second variant type does not allow tag(s) `C
# val revapply : 'a -> ('a -> 'b) -> 'b = <fun>
# val f : 'a -> [< `Foo ] -> 'a = <fun>
#

View File

@ -1,4 +1,15 @@
let rec x = [| x |]; 1.;;
[%%expect{|
Line _, characters 12-19:
Warning 10: this expression should have type unit.
Line _, characters 12-23:
Error: This kind of expression is not allowed as right-hand side of `let rec'
|}];;
let rec x = let u = [|y|] in 10. and y = 1.;;
[%%expect{|
Line _, characters 16-17:
Warning 26: unused variable u.
Line _, characters 12-32:
Error: This kind of expression is not allowed as right-hand side of `let rec'
|}];;

View File

@ -1,18 +0,0 @@
# Characters 13-20:
let rec x = [| x |]; 1.;;
^^^^^^^
Warning 10: this expression should have type unit.
Characters 13-24:
let rec x = [| x |]; 1.;;
^^^^^^^^^^^
Error: This kind of expression is not allowed as right-hand side of `let rec'
# Characters 17-18:
let rec x = let u = [|y|] in 10. and y = 1.;;
^
Warning 26: unused variable u.
Characters 13-33:
let rec x = let u = [|y|] in 10. and y = 1.;;
^^^^^^^^^^^^^^^^^^^^
Error: This kind of expression is not allowed as right-hand side of `let rec'
#

View File

@ -6,9 +6,34 @@ let f : < .. > t -> unit = fun _ -> ();;
let g : [< `b] t -> unit = fun _ -> ();;
let h : [> `b] t -> unit = fun _ -> ();;
[%%expect{|
type 'a t
type a
val f : < .. > t -> unit = <fun>
val g : [< `b ] t -> unit = <fun>
val h : [> `b ] t -> unit = <fun>
|}];;
let _ = fun (x : a t) -> f x;;
[%%expect{|
Line _, characters 27-28:
Error: This expression has type a t but an expression was expected of type
(< .. > as 'a) t
Type a is not compatible with type < .. > as 'a
|}];;
let _ = fun (x : a t) -> g x;;
[%%expect{|
Line _, characters 27-28:
Error: This expression has type a t but an expression was expected of type
([< `b ] as 'a) t
Type a is not compatible with type [< `b ] as 'a
|}];;
let _ = fun (x : a t) -> h x;;
[%%expect{|
Line _, characters 27-28:
Error: This expression has type a t but an expression was expected of type
([> `b ] as 'a) t
Type a is not compatible with type [> `b ] as 'a
|}];;

View File

@ -1,25 +0,0 @@
# type 'a t
type a
val f : < .. > t -> unit = <fun>
# val g : [< `b ] t -> unit = <fun>
# val h : [> `b ] t -> unit = <fun>
# Characters 28-29:
let _ = fun (x : a t) -> f x;;
^
Error: This expression has type a t but an expression was expected of type
(< .. > as 'a) t
Type a is not compatible with type < .. > as 'a
# Characters 28-29:
let _ = fun (x : a t) -> g x;;
^
Error: This expression has type a t but an expression was expected of type
([< `b ] as 'a) t
Type a is not compatible with type [< `b ] as 'a
# Characters 28-29:
let _ = fun (x : a t) -> h x;;
^
Error: This expression has type a t but an expression was expected of type
([> `b ] as 'a) t
Type a is not compatible with type [> `b ] as 'a
#

View File

@ -1,7 +1,18 @@
(* PR#7012 *)
type t = [ 'A_name | `Hi ];;
[%%expect{|
Line _, characters 11-18:
Error: The type 'A_name is not a polymorphic variant type
Hint: Did you mean `A_name?
|}];;
let f (x:'id_arg) = x;;
[%%expect{|
val f : 'id_arg -> 'id_arg = <fun>
|}];;
let f (x:'Id_arg) = x;;
[%%expect{|
val f : 'Id_arg -> 'Id_arg = <fun>
|}];;

View File

@ -1,9 +0,0 @@
# Characters 26-33:
type t = [ 'A_name | `Hi ];;
^^^^^^^
Error: The type 'A_name is not a polymorphic variant type
Hint: Did you mean `A_name?
# val f : 'id_arg -> 'id_arg = <fun>
# val f : 'Id_arg -> 'Id_arg = <fun>
#

View File

@ -1,38 +1,95 @@
(* undefined labels *)
type t = {x:int;y:int};;
{x=3;z=2};;
[%%expect{|
type t = { x : int; y : int; }
Line _, characters 5-6:
Error: Unbound record field z
|}];;
fun {x=3;z=2} -> ();;
[%%expect{|
Line _, characters 9-10:
Error: Unbound record field z
|}];;
(* mixed labels *)
{x=3; contents=2};;
[%%expect{|
Line _, characters 6-14:
Error: The record field contents belongs to the type 'a ref
but is mixed here with fields of type t
|}];;
(* private types *)
type u = private {mutable u:int};;
{u=3};;
[%%expect{|
type u = private { mutable u : int; }
Line _, characters 0-5:
Error: Cannot create values of the private type u
|}];;
fun x -> x.u <- 3;;
[%%expect{|
Line _, characters 11-12:
Error: Cannot assign field u of the private type u
|}];;
(* Punning and abbreviations *)
module M = struct
type t = {x: int; y: int}
end;;
[%%expect{|
module M : sig type t = { x : int; y : int; } end
|}];;
let f {M.x; y} = x+y;;
let r = {M.x=1; y=2};;
let z = f r;;
[%%expect{|
val f : M.t -> int = <fun>
val r : M.t = {M.x = 1; y = 2}
val z : int = 3
|}];;
(* messages *)
type foo = { mutable y:int };;
let f (r: int) = r.y <- 3;;
[%%expect{|
type foo = { mutable y : int; }
Line _, characters 17-18:
Error: This expression has type int but an expression was expected of type
foo
|}];;
(* bugs *)
type foo = { y: int; z: int };;
type bar = { x: int };;
let f (r: bar) = ({ r with z = 3 } : foo)
[%%expect{|
type foo = { y : int; z : int; }
type bar = { x : int; }
Line _, characters 20-21:
Error: This expression has type bar but an expression was expected of type
foo
|}];;
type foo = { x: int };;
let r : foo = { ZZZ.x = 2 };;
[%%expect{|
type foo = { x : int; }
Line _, characters 16-21:
Error: Unbound module ZZZ
|}];;
(ZZZ.X : int option);;
[%%expect{|
Line _, characters 1-6:
Error: Unbound module ZZZ
|}];;
(* PR#5865 *)
let f (x : Complex.t) = x.Complex.z;;
[%%expect{|
Line _, characters 26-35:
Error: Unbound record field Complex.z
|}];;

View File

@ -1,54 +0,0 @@
# type t = { x : int; y : int; }
# Characters 5-6:
{x=3;z=2};;
^
Error: Unbound record field z
# Characters 9-10:
fun {x=3;z=2} -> ();;
^
Error: Unbound record field z
# Characters 26-34:
{x=3; contents=2};;
^^^^^^^^
Error: The record field contents belongs to the type 'a ref
but is mixed here with fields of type t
# type u = private { mutable u : int; }
# Characters 0-5:
{u=3};;
^^^^^
Error: Cannot create values of the private type u
# Characters 11-12:
fun x -> x.u <- 3;;
^
Error: Cannot assign field u of the private type u
# module M : sig type t = { x : int; y : int; } end
# val f : M.t -> int = <fun>
# val r : M.t = {M.x = 1; y = 2}
# val z : int = 3
# type foo = { mutable y : int; }
# Characters 17-18:
let f (r: int) = r.y <- 3;;
^
Error: This expression has type int but an expression was expected of type
foo
# type foo = { y : int; z : int; }
# type bar = { x : int; }
# Characters 20-21:
let f (r: bar) = ({ r with z = 3 } : foo)
^
Error: This expression has type bar but an expression was expected of type
foo
# Characters 16-21:
let r : foo = { ZZZ.x = 2 };;
^^^^^
Error: Unbound module ZZZ
# Characters 2-7:
(ZZZ.X : int option);;
^^^^^
Error: Unbound module ZZZ
# Characters 41-50:
let f (x : Complex.t) = x.Complex.z;;
^^^^^^^^^
Error: Unbound record field Complex.z
#

View File

@ -1,54 +0,0 @@
# type t = { x : int; y : int; }
# Characters 5-6:
{x=3;z=2};;
^
Error: Unbound record field z
# Characters 9-10:
fun {x=3;z=2} -> ();;
^
Error: Unbound record field z
# Characters 26-34:
{x=3; contents=2};;
^^^^^^^^
Error: The record field contents belongs to the type 'a ref
but is mixed here with fields of type t
# type u = private { mutable u : int; }
# Characters 0-5:
{u=3};;
^^^^^
Error: Cannot create values of the private type u
# Characters 11-12:
fun x -> x.u <- 3;;
^
Error: Cannot assign field u of the private type u
# module M : sig type t = { x : int; y : int; } end
# val f : M.t -> int = <fun>
# val r : M.t = {M.x = 1; y = 2}
# val z : int = 3
# type foo = { mutable y : int; }
# Characters 17-18:
let f (r: int) = r.y <- 3;;
^
Error: This expression has type int but an expression was expected of type
foo
# type foo = { y : int; z : int; }
# type bar = { x : int; }
# Characters 20-21:
let f (r: bar) = ({ r with z = 3 } : foo)
^
Error: This expression has type bar but an expression was expected of type
foo
# Characters 16-21:
let r : foo = { ZZZ.x = 2 };;
^^^^^
Error: Unbound module ZZZ
# Characters 2-7:
(ZZZ.X : int option);;
^^^^^
Error: Unbound module ZZZ
# Characters 41-50:
let f (x : Complex.t) = x.Complex.z;;
^^^^^^^^^
Error: Unbound record field Complex.z
#

View File

@ -6,3 +6,15 @@ end = struct
type t = A | B
let f = function A | B -> 0
end;;
[%%expect{|
Line _, characters 6-61:
Error: Signature mismatch:
Modules do not match:
sig type t = X.t = A | B val f : t -> int end
is not included in
sig type t = int * bool end
Type declarations do not match:
type t = X.t = A | B
is not included in
type t = int * bool
|}];;

View File

@ -1,16 +0,0 @@
# Characters 61-116:
......struct
type t = A | B
let f = function A | B -> 0
end..
Error: Signature mismatch:
Modules do not match:
sig type t = X.t = A | B val f : t -> int end
is not included in
sig type t = int * bool end
Type declarations do not match:
type t = X.t = A | B
is not included in
type t = int * bool
#

View File

@ -9,3 +9,8 @@ let f : type t. t prod -> _ = function Prod ->
end
in ()
;;
[%%expect{|
type _ prod = Prod : ('a * 'y) prod
Line _, characters 6-20:
Error: The type abbreviation d is cyclic
|}];;

View File

@ -1,7 +0,0 @@
# type _ prod = Prod : ('a * 'y) prod
# Characters 82-96:
type d = d * d
^^^^^^^^^^^^^^
Error: The type abbreviation d is cyclic
#

View File

@ -1,7 +0,0 @@
# type _ prod = Prod : ('a * 'y) prod
# Characters 82-96:
type d = d * d
^^^^^^^^^^^^^^
Error: The type abbreviation d is cyclic
#

View File

@ -14,5 +14,5 @@
#**************************************************************************
BASEDIR=../..
include $(BASEDIR)/makefiles/Makefile.toplevel
include $(BASEDIR)/makefiles/Makefile.expect
include $(BASEDIR)/makefiles/Makefile.common

View File

@ -2,9 +2,17 @@
module type S = sig type t and s = t end;;
module type S' = S with type t := int;;
[%%expect{|
module type S = sig type t and s = t end
module type S' = sig type s = int end
|}];;
module type S = sig module rec M : sig end and N : sig end end;;
module type S' = S with module M := String;;
[%%expect{|
module type S = sig module rec M : sig end and N : sig end end
module type S' = sig module rec N : sig end end
|}];;
(* with module type *)
(*
@ -30,33 +38,74 @@ type -'a t
class type c = object method m : [ `A ] t end;;
module M : sig val v : (#c as 'a) -> 'a end =
struct let v x = ignore (x :> c); x end;;
[%%expect{|
type -'a t
class type c = object method m : [ `A ] t end
module M : sig val v : (#c as 'a) -> 'a end
|}];;
(* PR#4838 *)
let id = let module M = struct end in fun x -> x;;
[%%expect{|
val id : 'a -> 'a = <fun>
|}];;
(* PR#4511 *)
let ko = let module M = struct end in fun _ -> ();;
[%%expect{|
val ko : 'a -> unit = <fun>
|}];;
(* PR#5993 *)
module M : sig type -'a t = private int end =
struct type +'a t = private int end
;;
[%%expect{|
Line _, characters 2-37:
Error: Signature mismatch:
Modules do not match:
sig type +'a t = private int end
is not included in
sig type -'a t = private int end
Type declarations do not match:
type +'a t = private int
is not included in
type -'a t = private int
Their variances do not agree.
|}];;
(* PR#6005 *)
module type A = sig type t = X of int end;;
type u = X of bool;;
module type B = A with type t = u;; (* fail *)
[%%expect{|
module type A = sig type t = X of int end
type u = X of bool
Line _, characters 23-33:
Error: This variant or record definition does not match that of type u
The types for field X are not equal.
|}];;
(* PR#5815 *)
(* ---> duplicated exception name is now an error *)
module type S = sig exception Foo of int exception Foo of bool end;;
[%%expect{|
Line _, characters 52-55:
Error: Multiple definition of the extension constructor name Foo.
Names must be unique in a given structure or signature.
|}];;
(* PR#6410 *)
module F(X : sig end) = struct let x = 3 end;;
F.x;; (* fail *)
[%%expect{|
module F : functor (X : sig end) -> sig val x : int end
Line _, characters 0-3:
Error: The module F is a functor, not a structure
|}];;

View File

@ -1,41 +0,0 @@
# module type S = sig type t and s = t end
# module type S' = sig type s = int end
# module type S = sig module rec M : sig end and N : sig end end
# module type S' = sig module rec N : sig end end
# * * * * * * * * * * * * * * * * type -'a t
class type c = object method m : [ `A ] t end
# module M : sig val v : (#c as 'a) -> 'a end
# val id : 'a -> 'a = <fun>
# val ko : 'a -> unit = <fun>
# Characters 64-99:
struct type +'a t = private int end
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Signature mismatch:
Modules do not match:
sig type +'a t = private int end
is not included in
sig type -'a t = private int end
Type declarations do not match:
type +'a t = private int
is not included in
type -'a t = private int
Their variances do not agree.
# module type A = sig type t = X of int end
# type u = X of bool
# Characters 23-33:
module type B = A with type t = u;; (* fail *)
^^^^^^^^^^
Error: This variant or record definition does not match that of type u
The types for field X are not equal.
# Characters 121-124:
module type S = sig exception Foo of int exception Foo of bool end;;
^^^
Error: Multiple definition of the extension constructor name Foo.
Names must be unique in a given structure or signature.
# module F : functor (X : sig end) -> sig val x : int end
# Characters 0-3:
F.x;; (* fail *)
^^^
Error: The module F is a functor, not a structure
#

View File

@ -1,41 +0,0 @@
# module type S = sig type t and s = t end
# module type S' = sig type s = int end
# module type S = sig module rec M : sig end and N : sig end end
# module type S' = sig module rec N : sig end end
# * * * * * * * * * * * * * * * * type -'a t
class type c = object method m : [ `A ] t end
# module M : sig val v : (#c as 'a) -> 'a end
# val id : 'a -> 'a = <fun>
# val ko : 'a -> unit = <fun>
# Characters 64-99:
struct type +'a t = private int end
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Signature mismatch:
Modules do not match:
sig type +'a t = private int end
is not included in
sig type -'a t = private int end
Type declarations do not match:
type +'a t = private int
is not included in
type -'a t = private int
Their variances do not agree.
# module type A = sig type t = X of int end
# type u = X of bool
# Characters 23-33:
module type B = A with type t = u;; (* fail *)
^^^^^^^^^^
Error: This variant or record definition does not match that of type u
The types for field X are not equal.
# Characters 121-124:
module type S = sig exception Foo of int exception Foo of bool end;;
^^^
Error: Multiple definition of the extension constructor name Foo.
Names must be unique in a given structure or signature.
# module F : functor (X : sig end) -> sig val x : int end
# Characters 0-3:
F.x;; (* fail *)
^^^
Error: The module F is a functor, not a structure
#

View File

@ -1,3 +0,0 @@
module L = List
module S = String
module D' = D

View File

@ -6,22 +6,100 @@ C'.chr 66;;
module C3 = struct include Char end;;
C3.chr 66;;
[%%expect{|
module C = Char
- : char = 'B'
module C' :
sig
external code : char -> int = "%identity"
val chr : int -> char
val escaped : char -> string
val lowercase : char -> char
val uppercase : char -> char
val lowercase_ascii : char -> char
val uppercase_ascii : char -> char
type t = char
val compare : t -> t -> int
val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
- : char = 'B'
module C3 :
sig
external code : char -> int = "%identity"
val chr : int -> char
val escaped : char -> string
val lowercase : char -> char
val uppercase : char -> char
val lowercase_ascii : char -> char
val uppercase_ascii : char -> char
type t = char
val compare : t -> t -> int
val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
- : char = 'B'
|}];;
let f x = let module M = struct module L = List end in M.L.length x;;
let g x = let module L = List in L.length (L.map succ x);;
[%%expect{|
val f : 'a list -> int = <fun>
val g : int list -> int = <fun>
|}];;
module F(X:sig end) = Char;;
module C4 = F(struct end);;
C4.chr 66;;
[%%expect{|
module F :
functor (X : sig end) ->
sig
external code : char -> int = "%identity"
val chr : int -> char
val escaped : char -> string
val lowercase : char -> char
val uppercase : char -> char
val lowercase_ascii : char -> char
val uppercase_ascii : char -> char
type t = char
val compare : t -> t -> int
val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
module C4 :
sig
external code : char -> int = "%identity"
val chr : int -> char
val escaped : char -> string
val lowercase : char -> char
val uppercase : char -> char
val lowercase_ascii : char -> char
val uppercase_ascii : char -> char
type t = char
val compare : t -> t -> int
val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
- : char = 'B'
|}];;
module G(X:sig end) = struct module M = X end;; (* does not alias X *)
module M = G(struct end);;
[%%expect{|
module G : functor (X : sig end) -> sig module M : sig end end
module M : sig module M : sig end end
|}];;
module M' = struct
module N = struct let x = 1 end
module N' = N
end;;
M'.N'.x;;
[%%expect{|
module M' : sig module N : sig val x : int end module N' = N end
- : int = 1
|}];;
module M'' : sig module N' : sig val x : int end end = M';;
M''.N'.x;;
@ -30,12 +108,25 @@ module M3 : sig module N' : sig val x : int end end = struct include M' end;;
M3.N'.x;;
module M3' : sig module N' : sig val x : int end end = M2;;
M3'.N'.x;;
[%%expect{|
module M'' : sig module N' : sig val x : int end end
- : int = 1
module M2 : sig module N = M'.N module N' = M'.N' end
module M3 : sig module N' : sig val x : int end end
- : int = 1
module M3' : sig module N' : sig val x : int end end
- : int = 1
|}];;
module M4 : sig module N' : sig val x : int end end = struct
module N = struct let x = 1 end
module N' = N
end;;
M4.N'.x;;
[%%expect{|
module M4 : sig module N' : sig val x : int end end
- : int = 1
|}];;
module F(X:sig end) = struct
module N = struct let x = 1 end
@ -44,6 +135,14 @@ end;;
module G : functor(X:sig end) -> sig module N' : sig val x : int end end = F;;
module M5 = G(struct end);;
M5.N'.x;;
[%%expect{|
module F :
functor (X : sig end) ->
sig module N : sig val x : int end module N' = N end
module G : functor (X : sig end) -> sig module N' : sig val x : int end end
module M5 : sig module N' : sig val x : int end end
- : int = 1
|}];;
module M = struct
module D = struct let y = 3 end
@ -59,6 +158,19 @@ M2.N'.x;;
open M;;
N'.x;;
[%%expect{|
module M :
sig
module D : sig val y : int end
module N : sig val x : int end
module N' = N
end
module M1 : sig module N : sig val x : int end module N' = N end
- : int = 1
module M2 : sig module N' : sig val x : int end end
- : int = 1
- : int = 1
|}];;
module M = struct
module C = Char
@ -71,12 +183,28 @@ M1.C'.escaped 'A';;
module M2 : sig module C' : sig val chr : int -> char end end =
(M : sig module C : sig val chr : int -> char end module C' = C end);;
M2.C'.chr 66;;
[%%expect{|
module M : sig module C = Char module C' = C end
module M1 :
sig module C : sig val escaped : char -> string end module C' = C end
- : string = "A"
module M2 : sig module C' : sig val chr : int -> char end end
- : char = 'B'
|}];;
StdLabels.List.map;;
[%%expect{|
- : f:('a -> 'b) -> 'a list -> 'b list = <fun>
|}];;
module Q = Queue;;
exception QE = Q.Empty;;
try Q.pop (Q.create ()) with QE -> "Ok";;
[%%expect{|
module Q = Queue
exception QE
- : string = "Ok"
|}];;
module type Complex = module type of Complex with type t = Complex.t;;
module M : sig module C : Complex end = struct module C = Complex end;;
@ -84,14 +212,131 @@ module M : sig module C : Complex end = struct module C = Complex end;;
module C = Complex;;
C.one.Complex.re;;
include C;;
[%%expect{|
module type Complex =
sig
type t = Complex.t = { re : float; im : float; }
val zero : t
val one : t
val i : t
val neg : t -> t
val conj : t -> t
val add : t -> t -> t
val sub : t -> t -> t
val mul : t -> t -> t
val inv : t -> t
val div : t -> t -> t
val sqrt : t -> t
val norm2 : t -> float
val norm : t -> float
val arg : t -> float
val polar : float -> float -> t
val exp : t -> t
val log : t -> t
val pow : t -> t -> t
end
module M : sig module C : Complex end
module C = Complex
- : float = 1.
type t = Complex.t = { re : float; im : float; }
val zero : t = {re = 0.; im = 0.}
val one : t = {re = 1.; im = 0.}
val i : t = {re = 0.; im = 1.}
val neg : t -> t = <fun>
val conj : t -> t = <fun>
val add : t -> t -> t = <fun>
val sub : t -> t -> t = <fun>
val mul : t -> t -> t = <fun>
val inv : t -> t = <fun>
val div : t -> t -> t = <fun>
val sqrt : t -> t = <fun>
val norm2 : t -> float = <fun>
val norm : t -> float = <fun>
val arg : t -> float = <fun>
val polar : float -> float -> t = <fun>
val exp : t -> t = <fun>
val log : t -> t = <fun>
val pow : t -> t -> t = <fun>
|}];;
module F(X:sig module C = Char end) = struct module C = X.C end;;
[%%expect{|
module F : functor (X : sig module C = Char end) -> sig module C = Char end
|}];;
(* Applicative functors *)
module S = String
module StringSet = Set.Make(String)
module SSet = Set.Make(S);;
let f (x : StringSet.t) = (x : SSet.t);;
[%%expect{|
module S = String
module StringSet :
sig
type elt = String.t
type t = Set.Make(String).t
val empty : t
val is_empty : t -> bool
val mem : elt -> t -> bool
val add : elt -> t -> t
val singleton : elt -> t
val remove : elt -> t -> t
val union : t -> t -> t
val inter : t -> t -> t
val diff : t -> t -> t
val compare : t -> t -> int
val equal : t -> t -> bool
val subset : t -> t -> bool
val iter : (elt -> unit) -> t -> unit
val map : (elt -> elt) -> t -> t
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
val for_all : (elt -> bool) -> t -> bool
val exists : (elt -> bool) -> t -> bool
val filter : (elt -> bool) -> t -> t
val partition : (elt -> bool) -> t -> t * t
val cardinal : t -> int
val elements : t -> elt list
val min_elt : t -> elt
val max_elt : t -> elt
val choose : t -> elt
val split : elt -> t -> t * bool * t
val find : elt -> t -> elt
val of_list : elt list -> t
end
module SSet :
sig
type elt = S.t
type t = Set.Make(S).t
val empty : t
val is_empty : t -> bool
val mem : elt -> t -> bool
val add : elt -> t -> t
val singleton : elt -> t
val remove : elt -> t -> t
val union : t -> t -> t
val inter : t -> t -> t
val diff : t -> t -> t
val compare : t -> t -> int
val equal : t -> t -> bool
val subset : t -> t -> bool
val iter : (elt -> unit) -> t -> unit
val map : (elt -> elt) -> t -> t
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
val for_all : (elt -> bool) -> t -> bool
val exists : (elt -> bool) -> t -> bool
val filter : (elt -> bool) -> t -> t
val partition : (elt -> bool) -> t -> t * t
val cardinal : t -> int
val elements : t -> elt list
val min_elt : t -> elt
val max_elt : t -> elt
val choose : t -> elt
val split : elt -> t -> t * bool * t
val find : elt -> t -> elt
val of_list : elt list -> t
end
val f : StringSet.t -> SSet.t = <fun>
|}];;
(* Also using include (cf. Leo's mail 2013-11-16) *)
module F (M : sig end) : sig type t end = struct type t = int end
@ -101,6 +346,13 @@ module T = struct
end;;
include T;;
let f (x : t) : T.t = x ;;
[%%expect{|
module F : functor (M : sig end) -> sig type t end
module T : sig module M : sig end type t = F(M).t end
module M = T.M
type t = F(M).t
val f : t -> T.t = <fun>
|}];;
(* PR#4049 *)
(* This works thanks to abbreviations *)
@ -111,6 +363,47 @@ module A = struct
end
module A1 = A;;
A1.empty = A.empty;;
[%%expect{|
module A :
sig
module B : sig type t val compare : 'a -> 'b -> int end
module S :
sig
type elt = B.t
type t = Set.Make(B).t
val empty : t
val is_empty : t -> bool
val mem : elt -> t -> bool
val add : elt -> t -> t
val singleton : elt -> t
val remove : elt -> t -> t
val union : t -> t -> t
val inter : t -> t -> t
val diff : t -> t -> t
val compare : t -> t -> int
val equal : t -> t -> bool
val subset : t -> t -> bool
val iter : (elt -> unit) -> t -> unit
val map : (elt -> elt) -> t -> t
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
val for_all : (elt -> bool) -> t -> bool
val exists : (elt -> bool) -> t -> bool
val filter : (elt -> bool) -> t -> t
val partition : (elt -> bool) -> t -> t * t
val cardinal : t -> int
val elements : t -> elt list
val min_elt : t -> elt
val max_elt : t -> elt
val choose : t -> elt
val split : elt -> t -> t * bool * t
val find : elt -> t -> elt
val of_list : elt list -> t
end
val empty : S.t
end
module A1 = A
- : bool = true
|}];;
(* PR#3476 *)
(* Does not work yet *)
@ -125,6 +418,18 @@ module F (Y : sig type t end) (M : sig type t = Y.t end) = struct end;;
module G = F (M.Y);;
(*module N = G (M);;
module N = F (M.Y) (M);;*)
[%%expect{|
module FF : functor (X : sig end) -> sig type t end
module M :
sig
module X : sig end
module Y : sig type t = FF(X).t end
type t = Y.t
end
module F :
functor (Y : sig type t end) (M : sig type t = Y.t end) -> sig end
module G : functor (M : sig type t = M.Y.t end) -> sig end
|}];;
(* PR#6307 *)
@ -137,6 +442,15 @@ module F (L : (module type of L1)) = struct end;;
module F1 = F(L1);; (* ok *)
module F2 = F(L2);; (* should succeed too *)
[%%expect{|
module A1 : sig end
module A2 : sig end
module L1 : sig module X = A1 end
module L2 : sig module X = A2 end
module F : functor (L : sig module X : sig end end) -> sig end
module F1 : sig end
module F2 : sig end
|}];;
(* Counter example: why we need to be careful with PR#6307 *)
module Int = struct type t = int let compare = compare end
@ -155,6 +469,58 @@ module type S' = sig
module I = Int2
include S with module I := I
end;; (* fail *)
[%%expect{|
module Int : sig type t = int val compare : 'a -> 'a -> int end
module SInt :
sig
type elt = Int.t
type t = Set.Make(Int).t
val empty : t
val is_empty : t -> bool
val mem : elt -> t -> bool
val add : elt -> t -> t
val singleton : elt -> t
val remove : elt -> t -> t
val union : t -> t -> t
val inter : t -> t -> t
val diff : t -> t -> t
val compare : t -> t -> int
val equal : t -> t -> bool
val subset : t -> t -> bool
val iter : (elt -> unit) -> t -> unit
val map : (elt -> elt) -> t -> t
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
val for_all : (elt -> bool) -> t -> bool
val exists : (elt -> bool) -> t -> bool
val filter : (elt -> bool) -> t -> t
val partition : (elt -> bool) -> t -> t * t
val cardinal : t -> int
val elements : t -> elt list
val min_elt : t -> elt
val max_elt : t -> elt
val choose : t -> elt
val split : elt -> t -> t * bool * t
val find : elt -> t -> elt
val of_list : elt list -> t
end
type (_, _) eq = Eq : ('a, 'a) eq
type wrap = W of (SInt.t, SInt.t) eq
module M :
sig
module I = Int
type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(I).t) eq
end
module type S =
sig
module I = Int
type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(I).t) eq
end
module Int2 : sig type t = int val compare : 'a -> 'a -> int end
Line _, characters 10-30:
Error: In this `with' constraint, the new definition of I
does not match its original definition in the constrained signature:
Modules do not match: (module Int2) is not included in (module Int)
|}];;
(* (* if the above succeeded, one could break invariants *)
module rec M2 : S' = M2;; (* should succeed! (but this is bad) *)
@ -178,6 +544,22 @@ module M = struct
end
end;;
module type S = module type of M ;;
[%%expect{|
module M :
sig
module N : sig module I = Int end
module P : sig module I = N.I end
module Q :
sig type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(P.I).t) eq end
end
module type S =
sig
module N : sig module I = Int end
module P : sig module I = N.I end
module Q :
sig type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(P.I).t) eq end
end
|}];;
module M = struct
module N = struct module I = Int end
@ -187,18 +569,57 @@ module M = struct
end
end;;
module type S = module type of M ;;
[%%expect{|
module M :
sig
module N : sig module I = Int end
module P : sig module I = N.I end
module Q :
sig type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(N.I).t) eq end
end
module type S =
sig
module N : sig module I = Int end
module P :
sig module I : sig type t = int val compare : 'a -> 'a -> int end end
module Q :
sig type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(N.I).t) eq end
end
|}];;
(* PR#6365 *)
module type S = sig module M : sig type t val x : t end end;;
module H = struct type t = A let x = A end;;
module H' = H;;
module type S' = S with module M = H';; (* shouldn't introduce an alias *)
[%%expect{|
module type S = sig module M : sig type t val x : t end end
module H : sig type t = A val x : t end
module H' = H
module type S' = sig module M : sig type t = H.t = A val x : t end end
|}];;
(* PR#6376 *)
module type Alias = sig module N : sig end module M = N end;;
module F (X : sig end) = struct type t end;;
module type A = Alias with module N := F(List);;
module rec Bad : A = Bad;;
[%%expect{|
module type Alias = sig module N : sig end module M = N end
module F : functor (X : sig end) -> sig type t end
Line _:
Error: Module type declarations do not match:
module type A = sig module M = F(List) end
does not match
module type A = sig module M = F(List) end
At position module type A = <here>
Modules do not match:
sig module M = F(List) end
is not included in
sig module M = F(List) end
At position module type A = sig module M : <here> end
Module F(List) cannot be aliased
|}];;
(* Shinwell 2014-04-23 *)
module B = struct
@ -215,17 +636,30 @@ module K = struct
end;;
let x : K.N.t = "foo";;
[%%expect{|
module B : sig module R : sig type t = string end module O = R end
module K : sig module E = B module N = E.O end
val x : K.N.t = "foo"
|}];;
(* PR#6465 *)
module M = struct type t = A module B = struct type u = B end end;;
module P : sig type t = M.t = A module B = M.B end = M;; (* should be ok *)
module P : sig type t = M.t = A module B = M.B end = struct include M end;;
[%%expect{|
module M : sig type t = A module B : sig type u = B end end
module P : sig type t = M.t = A module B = M.B end
module P : sig type t = M.t = A module B = M.B end
|}];;
module type S = sig
module M : sig module P : sig end end
module Q = M
end;;
[%%expect{|
module type S = sig module M : sig module P : sig end end module Q = M end
|}];;
module type S = sig
module M : sig module N : sig end module P : sig end end
module Q : sig module N = M.N module P = M.P end
@ -235,6 +669,19 @@ module R = struct
module Q = M
end;;
module R' : S = R;; (* should be ok *)
[%%expect{|
module type S =
sig
module M : sig module N : sig end module P : sig end end
module Q : sig module N = M.N module P = M.P end
end
module R :
sig
module M : sig module N : sig end module P : sig end end
module Q = M
end
module R' : S
|}];;
(* PR#6578 *)
@ -242,5 +689,14 @@ module M = struct let f x = x end
module rec R : sig module M : sig val f : 'a -> 'a end end =
struct module M = M end;;
R.M.f 3;;
[%%expect{|
module M : sig val f : 'a -> 'a end
module rec R : sig module M : sig val f : 'a -> 'a end end
- : int = 3
|}];;
module rec R : sig module M = M end = struct module M = M end;;
R.M.f 3;;
[%%expect{|
module rec R : sig module M = M end
- : int = 3
|}];;

View File

@ -1,406 +0,0 @@
# module C = Char
# - : char = 'B'
# module C' :
sig
external code : char -> int = "%identity"
val chr : int -> char
val escaped : char -> string
val lowercase : char -> char
val uppercase : char -> char
val lowercase_ascii : char -> char
val uppercase_ascii : char -> char
type t = char
val compare : t -> t -> int
val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
# - : char = 'B'
# module C3 :
sig
external code : char -> int = "%identity"
val chr : int -> char
val escaped : char -> string
val lowercase : char -> char
val uppercase : char -> char
val lowercase_ascii : char -> char
val uppercase_ascii : char -> char
type t = char
val compare : t -> t -> int
val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
# - : char = 'B'
# val f : 'a list -> int = <fun>
# val g : int list -> int = <fun>
# module F :
functor (X : sig end) ->
sig
external code : char -> int = "%identity"
val chr : int -> char
val escaped : char -> string
val lowercase : char -> char
val uppercase : char -> char
val lowercase_ascii : char -> char
val uppercase_ascii : char -> char
type t = char
val compare : t -> t -> int
val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
# module C4 :
sig
external code : char -> int = "%identity"
val chr : int -> char
val escaped : char -> string
val lowercase : char -> char
val uppercase : char -> char
val lowercase_ascii : char -> char
val uppercase_ascii : char -> char
type t = char
val compare : t -> t -> int
val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
# - : char = 'B'
# module G : functor (X : sig end) -> sig module M : sig end end
# module M : sig module M : sig end end
# module M' : sig module N : sig val x : int end module N' = N end
# - : int = 1
# module M'' : sig module N' : sig val x : int end end
# - : int = 1
# module M2 : sig module N = M'.N module N' = M'.N' end
# module M3 : sig module N' : sig val x : int end end
# - : int = 1
# module M3' : sig module N' : sig val x : int end end
# - : int = 1
# module M4 : sig module N' : sig val x : int end end
# - : int = 1
# module F :
functor (X : sig end) ->
sig module N : sig val x : int end module N' = N end
# module G : functor (X : sig end) -> sig module N' : sig val x : int end end
# module M5 : sig module N' : sig val x : int end end
# - : int = 1
# module M :
sig
module D : sig val y : int end
module N : sig val x : int end
module N' = N
end
# module M1 : sig module N : sig val x : int end module N' = N end
# - : int = 1
# module M2 : sig module N' : sig val x : int end end
# - : int = 1
# # - : int = 1
# module M : sig module C = Char module C' = C end
# module M1 :
sig module C : sig val escaped : char -> string end module C' = C end
# - : string = "A"
# module M2 : sig module C' : sig val chr : int -> char end end
# - : char = 'B'
# - : f:('a -> 'b) -> 'a list -> 'b list = <fun>
# module Q = Queue
# exception QE
# - : string = "Ok"
# module type Complex =
sig
type t = Complex.t = { re : float; im : float; }
val zero : t
val one : t
val i : t
val neg : t -> t
val conj : t -> t
val add : t -> t -> t
val sub : t -> t -> t
val mul : t -> t -> t
val inv : t -> t
val div : t -> t -> t
val sqrt : t -> t
val norm2 : t -> float
val norm : t -> float
val arg : t -> float
val polar : float -> float -> t
val exp : t -> t
val log : t -> t
val pow : t -> t -> t
end
# module M : sig module C : Complex end
# module C = Complex
# - : float = 1.
# type t = Complex.t = { re : float; im : float; }
val zero : t = {re = 0.; im = 0.}
val one : t = {re = 1.; im = 0.}
val i : t = {re = 0.; im = 1.}
val neg : t -> t = <fun>
val conj : t -> t = <fun>
val add : t -> t -> t = <fun>
val sub : t -> t -> t = <fun>
val mul : t -> t -> t = <fun>
val inv : t -> t = <fun>
val div : t -> t -> t = <fun>
val sqrt : t -> t = <fun>
val norm2 : t -> float = <fun>
val norm : t -> float = <fun>
val arg : t -> float = <fun>
val polar : float -> float -> t = <fun>
val exp : t -> t = <fun>
val log : t -> t = <fun>
val pow : t -> t -> t = <fun>
# module F : functor (X : sig module C = Char end) -> sig module C = Char end
# module S = String
module StringSet :
sig
type elt = String.t
type t = Set.Make(String).t
val empty : t
val is_empty : t -> bool
val mem : elt -> t -> bool
val add : elt -> t -> t
val singleton : elt -> t
val remove : elt -> t -> t
val union : t -> t -> t
val inter : t -> t -> t
val diff : t -> t -> t
val compare : t -> t -> int
val equal : t -> t -> bool
val subset : t -> t -> bool
val iter : (elt -> unit) -> t -> unit
val map : (elt -> elt) -> t -> t
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
val for_all : (elt -> bool) -> t -> bool
val exists : (elt -> bool) -> t -> bool
val filter : (elt -> bool) -> t -> t
val partition : (elt -> bool) -> t -> t * t
val cardinal : t -> int
val elements : t -> elt list
val min_elt : t -> elt
val max_elt : t -> elt
val choose : t -> elt
val split : elt -> t -> t * bool * t
val find : elt -> t -> elt
val of_list : elt list -> t
end
module SSet :
sig
type elt = S.t
type t = Set.Make(S).t
val empty : t
val is_empty : t -> bool
val mem : elt -> t -> bool
val add : elt -> t -> t
val singleton : elt -> t
val remove : elt -> t -> t
val union : t -> t -> t
val inter : t -> t -> t
val diff : t -> t -> t
val compare : t -> t -> int
val equal : t -> t -> bool
val subset : t -> t -> bool
val iter : (elt -> unit) -> t -> unit
val map : (elt -> elt) -> t -> t
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
val for_all : (elt -> bool) -> t -> bool
val exists : (elt -> bool) -> t -> bool
val filter : (elt -> bool) -> t -> t
val partition : (elt -> bool) -> t -> t * t
val cardinal : t -> int
val elements : t -> elt list
val min_elt : t -> elt
val max_elt : t -> elt
val choose : t -> elt
val split : elt -> t -> t * bool * t
val find : elt -> t -> elt
val of_list : elt list -> t
end
# val f : StringSet.t -> SSet.t = <fun>
# module F : functor (M : sig end) -> sig type t end
module T : sig module M : sig end type t = F(M).t end
# module M = T.M
type t = F(M).t
# val f : t -> T.t = <fun>
# module A :
sig
module B : sig type t val compare : 'a -> 'b -> int end
module S :
sig
type elt = B.t
type t = Set.Make(B).t
val empty : t
val is_empty : t -> bool
val mem : elt -> t -> bool
val add : elt -> t -> t
val singleton : elt -> t
val remove : elt -> t -> t
val union : t -> t -> t
val inter : t -> t -> t
val diff : t -> t -> t
val compare : t -> t -> int
val equal : t -> t -> bool
val subset : t -> t -> bool
val iter : (elt -> unit) -> t -> unit
val map : (elt -> elt) -> t -> t
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
val for_all : (elt -> bool) -> t -> bool
val exists : (elt -> bool) -> t -> bool
val filter : (elt -> bool) -> t -> t
val partition : (elt -> bool) -> t -> t * t
val cardinal : t -> int
val elements : t -> elt list
val min_elt : t -> elt
val max_elt : t -> elt
val choose : t -> elt
val split : elt -> t -> t * bool * t
val find : elt -> t -> elt
val of_list : elt list -> t
end
val empty : S.t
end
module A1 = A
# - : bool = true
# module FF : functor (X : sig end) -> sig type t end
module M :
sig
module X : sig end
module Y : sig type t = FF(X).t end
type t = Y.t
end
module F :
functor (Y : sig type t end) (M : sig type t = Y.t end) -> sig end
# module G : functor (M : sig type t = M.Y.t end) -> sig end
# * module A1 : sig end
module A2 : sig end
module L1 : sig module X = A1 end
module L2 : sig module X = A2 end
# module F : functor (L : sig module X : sig end end) -> sig end
# module F1 : sig end
# module F2 : sig end
# module Int : sig type t = int val compare : 'a -> 'a -> int end
module SInt :
sig
type elt = Int.t
type t = Set.Make(Int).t
val empty : t
val is_empty : t -> bool
val mem : elt -> t -> bool
val add : elt -> t -> t
val singleton : elt -> t
val remove : elt -> t -> t
val union : t -> t -> t
val inter : t -> t -> t
val diff : t -> t -> t
val compare : t -> t -> int
val equal : t -> t -> bool
val subset : t -> t -> bool
val iter : (elt -> unit) -> t -> unit
val map : (elt -> elt) -> t -> t
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
val for_all : (elt -> bool) -> t -> bool
val exists : (elt -> bool) -> t -> bool
val filter : (elt -> bool) -> t -> t
val partition : (elt -> bool) -> t -> t * t
val cardinal : t -> int
val elements : t -> elt list
val min_elt : t -> elt
val max_elt : t -> elt
val choose : t -> elt
val split : elt -> t -> t * bool * t
val find : elt -> t -> elt
val of_list : elt list -> t
end
type (_, _) eq = Eq : ('a, 'a) eq
type wrap = W of (SInt.t, SInt.t) eq
module M :
sig
module I = Int
type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(I).t) eq
end
# module type S =
sig
module I = Int
type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(I).t) eq
end
# module Int2 : sig type t = int val compare : 'a -> 'a -> int end
# Characters 49-69:
include S with module I := I
^^^^^^^^^^^^^^^^^^^^
Error: In this `with' constraint, the new definition of I
does not match its original definition in the constrained signature:
Modules do not match: (module Int2) is not included in (module Int)
# * * * * * * * * * * * module M :
sig
module N : sig module I = Int end
module P : sig module I = N.I end
module Q :
sig type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(P.I).t) eq end
end
# module type S =
sig
module N : sig module I = Int end
module P : sig module I = N.I end
module Q :
sig type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(P.I).t) eq end
end
# module M :
sig
module N : sig module I = Int end
module P : sig module I = N.I end
module Q :
sig type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(N.I).t) eq end
end
# module type S =
sig
module N : sig module I = Int end
module P :
sig module I : sig type t = int val compare : 'a -> 'a -> int end end
module Q :
sig type wrap' = wrap = W of (Set.Make(Int).t, Set.Make(N.I).t) eq end
end
# module type S = sig module M : sig type t val x : t end end
# module H : sig type t = A val x : t end
# module H' = H
# module type S' = sig module M : sig type t = H.t = A val x : t end end
# module type Alias = sig module N : sig end module M = N end
# module F : functor (X : sig end) -> sig type t end
# Characters -1--1:
module type A = Alias with module N := F(List);;
Error: Module type declarations do not match:
module type A = sig module M = F(List) end
does not match
module type A = sig module M = F(List) end
At position module type A = <here>
Modules do not match:
sig module M = F(List) end
is not included in
sig module M = F(List) end
At position module type A = sig module M : <here> end
Module F(List) cannot be aliased
# Characters 17-18:
module rec Bad : A = Bad;;
^
Error: Unbound module type A
# module B : sig module R : sig type t = string end module O = R end
module K : sig module E = B module N = E.O end
# val x : K.N.t = "foo"
# module M : sig type t = A module B : sig type u = B end end
# module P : sig type t = M.t = A module B = M.B end
# module P : sig type t = M.t = A module B = M.B end
# module type S = sig module M : sig module P : sig end end module Q = M end
# module type S =
sig
module M : sig module N : sig end module P : sig end end
module Q : sig module N = M.N module P = M.P end
end
# module R :
sig
module M : sig module N : sig end module P : sig end end
module Q = M
end
# module R' : S
# module M : sig val f : 'a -> 'a end
module rec R : sig module M : sig val f : 'a -> 'a end end
# - : int = 3
# module rec R : sig module M = M end
# - : int = 3
#

View File

@ -1,18 +0,0 @@
open A
let f =
L.map S.capitalize
let () =
L.iter print_endline (f ["jacques"; "garrigue"])
module C : sig module L : module type of List end = struct include A end
(* The following introduces a (useless) dependency on A:
module C : sig module L : module type of List end = A
*)
include D'
(*
let () =
print_endline (string_of_int D'.M.y)
*)

View File

@ -1,5 +0,0 @@
# * * * * *
Characters 352-352:
Error: Syntax error
#

View File

@ -1,14 +0,0 @@
open A
let f =
L.map S.capitalize
let () =
L.iter print_endline (f ["jacques"; "garrigue"])
module C : sig module L : module type of List end = struct include A end
(* The following introduces a (useless) dependency on A:
module C : sig module L : module type of List end = A
*)
(* No dependency on D *)

View File

@ -1,5 +0,0 @@
# * *
Characters 312-312:
Error: Syntax error
#

View File

@ -1,4 +0,0 @@
open A
(*module type S = module type of D'.M*)
type t = Complex.t
type s = String.t

View File

@ -1,2 +0,0 @@
let x = 3
module M = struct let y = 5 end

View File

@ -1,5 +0,0 @@
#
Characters 42-42:
Error: Syntax error
#

View File

@ -5,6 +5,12 @@ module type S' = sig type t = int type u = bool end;;
are inferred *)
let f (x : (module S with type t = 'a and type u = 'b)) = (x : (module S'));;
let g x = (x : (module S with type t = 'a and type u = 'b) :> (module S'));;
[%%expect{|
module type S = sig type u type t end
module type S' = sig type t = int type u = bool end
val f : (module S with type t = int and type u = bool) -> (module S') = <fun>
val g : (module S with type t = int and type u = bool) -> (module S') = <fun>
|}];;
(* with subtyping it is also ok to forget some types *)
module type S2 = sig type u type t type w end;;
@ -14,8 +20,24 @@ let f2 (x : (module S2 with type t = 'a and type u = 'b)) =
(x : (module S'));; (* fail *)
let k (x : (module S2 with type t = 'a)) =
(x : (module S with type t = 'a));; (* fail *)
[%%expect{|
module type S2 = sig type u type t type w end
val g2 : (module S2 with type t = int and type u = bool) -> (module S') =
<fun>
val h : (module S2 with type t = 'a) -> (module S with type t = 'a) = <fun>
Line _, characters 3-4:
Error: This expression has type
(module S2 with type t = int and type u = bool)
but an expression was expected of type (module S')
|}];;
(* but you cannot forget values (no physical coercions) *)
module type S3 = sig type u type t val x : int end;;
let g3 x =
(x : (module S3 with type t = 'a and type u = 'b) :> (module S'));; (* fail *)
[%%expect{|
module type S3 = sig type u type t val x : int end
Line _, characters 2-67:
Error: Type (module S3 with type t = int and type u = bool)
is not a subtype of (module S')
|}];;

View File

@ -1,27 +0,0 @@
# module type S = sig type u type t end
# module type S' = sig type t = int type u = bool end
# * val f : (module S with type t = int and type u = bool) -> (module S') = <fun>
# val g : (module S with type t = int and type u = bool) -> (module S') = <fun>
# module type S2 = sig type u type t type w end
# val g2 : (module S2 with type t = int and type u = bool) -> (module S') =
<fun>
# val h : (module S2 with type t = 'a) -> (module S with type t = 'a) = <fun>
# Characters 63-64:
(x : (module S'));; (* fail *)
^
Error: This expression has type
(module S2 with type t = int and type u = bool)
but an expression was expected of type (module S')
# Characters 46-47:
(x : (module S with type t = 'a));; (* fail *)
^
Error: This expression has type (module S2 with type t = 'a)
but an expression was expected of type (module S with type t = 'a)
# module type S3 = sig type u type t val x : int end
# Characters 13-78:
(x : (module S3 with type t = 'a and type u = 'b) :> (module S'));; (* fail *)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Type (module S3 with type t = int and type u = bool)
is not a subtype of (module S')
#

View File

@ -6,24 +6,70 @@ let v = (module struct let x = 3 end : S);;
module F() = (val v);; (* ok *)
module G (X : sig end) : S = F ();; (* ok *)
module H (X : sig end) = (val v);; (* ok *)
[%%expect{|
module type S = sig val x : int end
val v : (module S) = <module>
module F : functor () -> S
module G : functor (X : sig end) -> S
module H : functor (X : sig end) -> S
|}];;
(* With type *)
module type S = sig type t val x : t end;;
let v = (module struct type t = int let x = 3 end : S);;
module F() = (val v);; (* ok *)
[%%expect{|
module type S = sig type t val x : t end
val v : (module S) = <module>
module F : functor () -> S
|}];;
module G (X : sig end) : S = F ();; (* fail *)
[%%expect{|
Line _, characters 29-33:
Error: This expression creates fresh types.
It is not allowed inside applicative functors.
|}];;
module H() = F();; (* ok *)
[%%expect{|
module H : functor () -> S
|}];;
(* Alias *)
module U = struct end;;
module M = F(struct end);; (* ok *)
[%%expect{|
module U : sig end
module M : S
|}];;
module M = F(U);; (* fail *)
[%%expect{|
Line _, characters 11-12:
Error: This is a generative functor. It can only be applied to ()
|}];;
(* Cannot coerce between applicative and generative *)
module F1 (X : sig end) = struct end;;
module F2 : functor () -> sig end = F1;; (* fail *)
[%%expect{|
module F1 : functor (X : sig end) -> sig end
Line _, characters 36-38:
Error: Signature mismatch:
Modules do not match:
functor (X : sig end) -> sig end
is not included in
functor () -> sig end
|}];;
module F3 () = struct end;;
module F4 : functor (X : sig end) -> sig end = F3;; (* fail *)
[%%expect{|
module F3 : functor () -> sig end
Line _, characters 47-49:
Error: Signature mismatch:
Modules do not match:
functor () -> sig end
is not included in
functor (X : sig end) -> sig end
|}];;
(* tests for shortened functor notation () *)
module X (X: sig end) (Y: sig end) = functor (Z: sig end) -> struct end;;
@ -32,3 +78,9 @@ module Y = functor (X: sig end) (Y:sig end) -> functor (Z: sig end) ->
module Z = functor (_: sig end) (_:sig end) (_: sig end) -> struct end;;
module GZ : functor (X: sig end) () (Z: sig end) -> sig end
= functor (X: sig end) () (Z: sig end) -> struct end;;
[%%expect{|
module X : functor (X : sig end) (Y : sig end) (Z : sig end) -> sig end
module Y : functor (X : sig end) (Y : sig end) (Z : sig end) -> sig end
module Z : sig end -> sig end -> sig end -> sig end
module GZ : functor (X : sig end) () (Z : sig end) -> sig end
|}];;

View File

@ -1,44 +0,0 @@
# module type S = sig val x : int end
# val v : (module S) = <module>
# module F : functor () -> S
# module G : functor (X : sig end) -> S
# module H : functor (X : sig end) -> S
# module type S = sig type t val x : t end
# val v : (module S) = <module>
# module F : functor () -> S
# Characters 29-33:
module G (X : sig end) : S = F ();; (* fail *)
^^^^
Error: This expression creates fresh types.
It is not allowed inside applicative functors.
# module H : functor () -> S
# module U : sig end
# module M : S
# Characters 11-12:
module M = F(U);; (* fail *)
^
Error: This is a generative functor. It can only be applied to ()
# module F1 : functor (X : sig end) -> sig end
# Characters 36-38:
module F2 : functor () -> sig end = F1;; (* fail *)
^^
Error: Signature mismatch:
Modules do not match:
functor (X : sig end) -> sig end
is not included in
functor () -> sig end
# module F3 : functor () -> sig end
# Characters 47-49:
module F4 : functor (X : sig end) -> sig end = F3;; (* fail *)
^^
Error: Signature mismatch:
Modules do not match:
functor () -> sig end
is not included in
functor (X : sig end) -> sig end
# module X : functor (X : sig end) (Y : sig end) (Z : sig end) -> sig end
# module Y : functor (X : sig end) (Y : sig end) (Z : sig end) -> sig end
# module Z : sig end -> sig end -> sig end -> sig end
# module GZ : functor (X : sig end) () (Z : sig end) -> sig end
#

View File

@ -6,9 +6,19 @@ end;;
module Good (X : S with type t := unit) = struct
let () = X.x
end;;
[%%expect{|
module type S = sig type t val x : t end
module Good : functor (X : sig val x : unit end) -> sig end
|}];;
module type T = sig module M : S end;;
module Bad (X : T with type M.t := unit) = struct
module Bad (X : T with type M.t = unit) = struct
let () = X.M.x
end;;
[%%expect{|
module type T = sig module M : S end
module Bad :
functor (X : sig module M : sig type t = unit val x : t end end) ->
sig end
|}];;

View File

@ -1,9 +0,0 @@
# module type S = sig type t val x : t end
# module Good : functor (X : sig val x : unit end) -> sig end
# module type T = sig module M : S end
# Characters 33-35:
module Bad (X : T with type M.t := unit) = struct
^^
Error: Syntax error
#

View File

@ -1,2 +1,7 @@
module F (X : sig end) = struct type t = int end;;
type t = F(Does_not_exist).t;;
[%%expect{|
module F : functor (X : sig end) -> sig type t = int end
Line _, characters 9-28:
Error: Unbound module Does_not_exist
|}];;

View File

@ -1,7 +0,0 @@
# module F : functor (X : sig end) -> sig type t = int end
# Characters 9-28:
type t = F(Does_not_exist).t;;
^^^^^^^^^^^^^^^^^^^
Error: Unbound module Does_not_exist
#

View File

@ -7,8 +7,19 @@ module type S = sig
end
end;;
module F (X : S) = X.M;;
[%%expect{|
module type S =
sig
class type c = object method m : int end
module M : sig class type d = c end
end
module F : functor (X : S) -> sig class type d = X.c end
|}];;
(* PR#6648 *)
module M = struct module N = struct let x = 1 end end;;
#show_module M;;
[%%expect{|
module M : sig module N : sig val x : int end end
|}];;

View File

@ -1,10 +0,0 @@
# module type S =
sig
class type c = object method m : int end
module M : sig class type d = c end
end
# module F : functor (X : S) -> sig class type d = X.c end
# module M : sig module N : sig val x : int end end
# module M : sig module N : sig ... end end
#