check with -principal too

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12290 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Jacques Garrigue 2012-03-29 06:26:38 +00:00
parent 7a8e3126ba
commit fc603f1a00
4 changed files with 662 additions and 2 deletions

View File

@ -216,7 +216,7 @@ end;;
let c3 = new int_comparable3 15;;
l#add (c3 :> int_comparable);;
(new sorted_list ())#add c3;; (* Echec : leq n'est pas binaire *)
(new sorted_list ())#add c3;; (* Error; strange message with -principal *)
let sort (l : #comparable list) = Sort.list (fun x -> x#leq) l;;
let pr l =

View File

@ -0,0 +1,358 @@
# class point :
int ->
object val mutable x : int method get_x : int method move : int -> unit end
# val p : point = <obj>
# - : int = 7
# - : unit = ()
# - : int = 10
# val q : < get_x : int; move : int -> unit > = <obj>
# - : int * int = (10, 17)
# class color_point :
int ->
string ->
object
val c : string
val mutable x : int
method color : string
method get_x : int
method move : int -> unit
end
# val p' : color_point = <obj>
# - : int * string = (5, "red")
# val l : point list = [<obj>; <obj>]
# val get_x : < get_x : 'a; .. > -> 'a = <fun>
# val set_x : < set_x : 'a; .. > -> 'a = <fun>
# - : int list = [10; 5]
# Characters 7-96:
......ref x_init = object
val mutable x = x_init
method get = x
method set y = x <- y
end..
Error: Some type variables are unbound in this type:
class ref :
'a ->
object
val mutable x : 'a
method get : 'a
method set : 'a -> unit
end
The method get has type 'a where 'a is unbound
# class ref :
int ->
object val mutable x : int method get : int method set : int -> unit end
# class ['a] ref :
'a -> object val mutable x : 'a method get : 'a method set : 'a -> unit end
# - : int = 2
# class ['a] circle :
'a ->
object
constraint 'a = < move : int -> unit; .. >
val mutable center : 'a
method center : 'a
method move : int -> unit
method set_center : 'a -> unit
end
# class ['a] circle :
'a ->
object
constraint 'a = #point
val mutable center : 'a
method center : 'a
method move : int -> unit
method set_center : 'a -> unit
end
# val c : point circle = <obj>
val c' : < color : string; get_x : int; move : int -> unit > circle = <obj>
# class ['a] color_circle :
'a ->
object
constraint 'a = #color_point
val mutable center : 'a
method center : 'a
method color : string
method move : int -> unit
method set_center : 'a -> unit
end
# Characters 28-29:
let c'' = new color_circle p;;
^
Error: This expression has type point but an expression was expected of type
#color_point
The first object type has no method color
# val c'' : color_point color_circle = <obj>
# - : color_point circle = <obj>
# Characters 0-21:
(c'' :> point circle);; (* Echec *)
^^^^^^^^^^^^^^^^^^^^^
Error: Type
color_point color_circle =
< center : color_point; color : string; move : int -> unit;
set_center : color_point -> unit >
is not a subtype of
point circle =
< center : point; move : int -> unit; set_center : point -> unit >
Type point = point is not a subtype of color_point = color_point
# Characters 9-55:
fun x -> (x : color_point color_circle :> point circle);;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Type
color_point color_circle =
< center : color_point; color : string; move : int -> unit;
set_center : color_point -> unit >
is not a subtype of
point circle =
< center : point; move : int -> unit; set_center : point -> unit >
Type point = point is not a subtype of color_point = color_point
# class printable_point :
int ->
object
val mutable x : int
method get_x : int
method move : int -> unit
method print : unit
end
# val p : printable_point = <obj>
# 7- : unit = ()
# Characters 85-102:
inherit printable_point y as super
^^^^^^^^^^^^^^^^^
Warning 13: the following instance variables are overridden by the class printable_point :
x
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
class printable_color_point :
int ->
string ->
object
val c : string
val mutable x : int
method color : string
method get_x : int
method move : int -> unit
method print : unit
end
# val p' : printable_color_point = <obj>
# (7, red)- : unit = ()
# class functional_point :
int ->
object ('a) val x : int method get_x : int method move : int -> 'a end
# val p : functional_point = <obj>
# - : int = 7
# - : int = 10
# - : int = 7
# - : #functional_point -> functional_point = <fun>
# class virtual ['a] lst :
unit ->
object
method virtual hd : 'a
method iter : ('a -> unit) -> unit
method map : ('a -> 'a) -> 'a lst
method virtual null : bool
method print : ('a -> unit) -> unit
method virtual tl : 'a lst
end
and ['a] nil :
unit ->
object
method hd : 'a
method iter : ('a -> unit) -> unit
method map : ('a -> 'a) -> 'a lst
method null : bool
method print : ('a -> unit) -> unit
method tl : 'a lst
end
and ['a] cons :
'a ->
'a lst ->
object
val h : 'a
val t : 'a lst
method hd : 'a
method iter : ('a -> unit) -> unit
method map : ('a -> 'a) -> 'a lst
method null : bool
method print : ('a -> unit) -> unit
method tl : 'a lst
end
# val l1 : int lst = <obj>
# (3::10::[])- : unit = ()
# val l2 : int lst = <obj>
# (4::11::[])- : unit = ()
# val map_list : ('a -> 'b) -> 'a lst -> 'b lst = <fun>
# val p1 : printable_color_point lst = <obj>
# ((3, red)::(10, red)::[])- : unit = ()
# class virtual comparable :
unit -> object ('a) method virtual leq : 'a -> bool end
# class int_comparable :
int -> object ('a) val x : int method leq : 'a -> bool method x : int end
# class int_comparable2 :
int ->
object ('a)
val x : int
val mutable x' : int
method leq : 'a -> bool
method set_x : int -> unit
method x : int
end
# class ['a] sorted_list :
unit ->
object
constraint 'a = #comparable
val mutable l : 'a list
method add : 'a -> unit
method hd : 'a
end
# val l : _#comparable sorted_list = <obj>
# val c : int_comparable = <obj>
# - : unit = ()
# val c2 : int_comparable2 = <obj>
# Characters 6-28:
l#add (c2 :> int_comparable);; (* Echec : 'a comp2 n'est un sous-type *)
^^^^^^^^^^^^^^^^^^^^^^
Error: Type
int_comparable2 =
< leq : int_comparable2 -> bool; set_x : int -> unit; x : int >
is not a subtype of
int_comparable = < leq : int_comparable -> bool; x : int >
Type int_comparable = < leq : int_comparable -> bool; x : int >
is not a subtype of
int_comparable2 =
< leq : int_comparable2 -> bool; set_x : int -> unit; x : int >
# - : unit = ()
# class int_comparable3 :
int ->
object
val mutable x : int
method leq : int_comparable -> bool
method setx : int -> unit
method x : int
end
# val c3 : int_comparable3 = <obj>
# - : unit = ()
# Characters 25-27:
(new sorted_list ())#add c3;; (* Error; strange message with -principal *)
^^
Error: This expression has type
int_comparable3 =
< leq : int_comparable -> bool; setx : int -> unit; x : int >
but an expression was expected of type
#comparable as 'a = < leq : 'a -> bool; .. >
Type int_comparable = < leq : int_comparable -> bool; x : int >
is not compatible with type 'a = < leq : 'a -> bool; .. >
The first object type has no method setx
# val sort : (#comparable as 'a) list -> 'a list = <fun>
# Characters 13-66:
List.map (fun c -> print_int c#x; print_string " ") l;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Warning 10: this expression should have type unit.
val pr : < x : int; .. > list -> unit = <fun>
# val l : int_comparable list = [<obj>; <obj>; <obj>]
# 5 2 4
- : unit = ()
# 2 4 5
- : unit = ()
# val l : int_comparable2 list = [<obj>; <obj>]
# 2 0
- : unit = ()
# 0 2
- : unit = ()
# val min : (#comparable as 'a) -> 'a -> 'a = <fun>
# - : int = 7
# - : int = 3
# class ['a] link :
'a ->
object ('b)
val mutable next : 'b option
val mutable x : 'a
method append : 'b option -> unit
method next : 'b option
method set_next : 'b option -> unit
method set_x : 'a -> unit
method x : 'a
end
# class ['a] double_link :
'a ->
object ('b)
val mutable next : 'b option
val mutable prev : 'b option
val mutable x : 'a
method append : 'b option -> unit
method next : 'b option
method prev : 'b option
method set_next : 'b option -> unit
method set_prev : 'b option -> unit
method set_x : 'a -> unit
method x : 'a
end
# val fold_right : ('a -> 'b -> 'b) -> 'a #link option -> 'b -> 'b = <fun>
# class calculator :
unit ->
object ('a)
val mutable acc : float
val mutable arg : float
val mutable equals : 'a -> float
method acc : float
method add : 'a
method arg : float
method enter : float -> 'a
method equals : float
method sub : 'a
end
# - : float = 5.
# - : float = 1.5
# - : float = 15.
# class calculator :
unit ->
object ('a)
val mutable acc : float
val mutable arg : float
val mutable equals : 'a -> float
method acc : float
method add : 'a
method arg : float
method enter : float -> 'a
method equals : float
method sub : 'a
end
# - : float = 5.
# - : float = 1.5
# - : float = 15.
# class calculator :
float ->
float ->
object
val acc : float
val arg : float
method add : calculator
method enter : float -> calculator
method equals : float
method sub : calculator
end
and calculator_add :
float ->
float ->
object
val acc : float
val arg : float
method add : calculator
method enter : float -> calculator
method equals : float
method sub : calculator
end
and calculator_sub :
float ->
float ->
object
val acc : float
val arg : float
method add : calculator
method enter : float -> calculator
method equals : float
method sub : calculator
end
# val calculator : calculator = <obj>
# - : float = 5.
# - : float = 1.5
# - : float = 15.
#

View File

@ -231,7 +231,7 @@ is not a subtype of
# val c3 : int_comparable3 = <obj>
# - : unit = ()
# Characters 25-27:
(new sorted_list ())#add c3;; (* Echec : leq n'est pas binaire *)
(new sorted_list ())#add c3;; (* Error; strange message with -principal *)
^^
Error: This expression has type
int_comparable3 =

View File

@ -0,0 +1,302 @@
# - : < x : int > ->
< x : int > -> < x : int > -> < x : int > * < x : int > * < x : int >
= <fun>
# class ['a] c : unit -> object constraint 'a = int method f : int c end
and ['a] d : unit -> object constraint 'a = int method f : int c end
# Characters 238-275:
........d () = object
inherit ['a] c ()
end..
Error: Some type variables are unbound in this type:
class d : unit -> object method f : 'a -> unit end
The method f has type 'a -> unit where 'a is unbound
# class virtual c : unit -> object end
and ['a] d :
unit -> object constraint 'a = < x : int; .. > method f : 'a -> int end
# class ['a] c : unit -> object constraint 'a = int end
and ['a] d : unit -> object constraint 'a = int #c end
# * class ['a] c :
'a -> object ('a) constraint 'a = < f : 'a; .. > method f : 'a end
# - : ('a c as 'a) -> 'a = <fun>
# * Characters 134-176:
......x () = object
method virtual f : int
end..
Error: This class should be virtual. The following methods are undefined : f
# Characters 139-147:
class virtual c ((x : 'a): < f : int >) = object (_ : 'a) end
^^^^^^^^
Error: This pattern cannot match self: it only matches values of type
< f : int >
# Characters 38-110:
......['a] c () = object
constraint 'a = int
method f x = (x : bool c)
end..
Error: The abbreviation c is used with parameters bool c
wich are incompatible with constraints int c
# class ['a, 'b] c :
unit ->
object
constraint 'a = int -> 'c
constraint 'b = 'a * < x : 'b > * 'c * 'd
method f : 'a -> 'b -> unit
end
# class ['a, 'b] d :
unit ->
object
constraint 'a = int -> 'c
constraint 'b = 'a * < x : 'b > * 'c * 'd
method f : 'a -> 'b -> unit
end
# val x : '_a list ref = {contents = []}
# Characters 6-50:
......['a] c () = object
method f = (x : 'a)
end..
Error: The type of this class,
class ['a] c :
unit -> object constraint 'a = '_b list ref method f : 'a end,
contains type variables that cannot be generalized
# Characters 24-52:
type 'a c = <f : 'a c; g : 'a d>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: In the definition of d, type int c should be 'a c
# type 'a c = < f : 'a c; g : 'a d >
and 'a d = < f : 'a c >
# type 'a c = < f : 'a c >
and 'a d = < f : int c >
# type 'a u = < x : 'a >
and 'a t = 'a t u
# Characters 18-32:
and 'a t = 'a t u;;
^^^^^^^^^^^^^^
Error: The type abbreviation t is cyclic
# type 'a u = 'a
# Characters 5-18:
type t = t u * t u;;
^^^^^^^^^^^^^
Error: The type abbreviation t is cyclic
# type t = < x : 'a > as 'a
# type 'a u = 'a
# - : t -> t u -> bool = <fun>
# - : t -> t u -> bool = <fun>
# module M :
sig
class ['a, 'b] c :
int ->
'b ->
object
constraint 'a = int -> bool
val x : float list
val y : 'b
method f : 'a -> unit
method g : 'b
end
end
# module M' :
sig
class virtual ['a, 'b] c :
int ->
'b ->
object
constraint 'a = int -> bool
val x : float list
val y : 'b
method f : 'a -> unit
method g : 'b
end
end
# class ['a, 'b] d :
unit ->
'b ->
object
constraint 'a = int -> bool
val x : float list
val y : 'b
method f : 'a -> unit
method g : 'b
end
# class ['a, 'b] e :
unit ->
'b ->
object
constraint 'a = int -> bool
val x : float list
val y : 'b
method f : 'a -> unit
method g : 'b
end
# - : string = "a"
# - : int = 10
# - : float = 7.1
# # - : bool = true
# module M : sig class ['a] c : unit -> object method f : 'a -> unit end end
# module M' : sig class ['a] c : unit -> object method f : 'a -> unit end end
# - : ('a #M.c as 'b) -> 'b = <fun>
# - : ('a #M'.c as 'b) -> 'b = <fun>
# class ['a] c : 'a #c -> object end
# class ['a] c : 'a #c -> object end
# class c : unit -> object method f : int end
and d : unit -> object method f : int end
# class e : unit -> object method f : int end
# - : int = 2
# Characters 30-34:
class c () = object val x = - true val y = -. () end;;
^^^^
Error: This expression has type bool but an expression was expected of type
int
# class c : unit -> object method f : int method g : int method h : int end
# class d : unit -> object method h : int method i : int method j : int end
# class e :
unit ->
object
method f : int
method g : int
method h : int
method i : int
method j : int
end
# val e : e = <obj>
# - : int * int * int * int * int = (1, 3, 2, 2, 3)
# class c : 'a -> object val a : 'a val x : int val y : int val z : int end
# class d : 'a -> object val b : 'a val t : int val u : int val z : int end
# Characters 43-46:
inherit c 5
^^^
Warning 13: the following instance variables are overridden by the class c :
x
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
Characters 53-58:
val y = 3
^^^^^
Warning 13: the instance variable y is overridden.
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
Characters 81-84:
inherit d 7
^^^
Warning 13: the following instance variables are overridden by the class d :
t z
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
Characters 91-96:
val u = 3
^^^^^
Warning 13: the instance variable u is overridden.
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
class e :
unit ->
object
val a : int
val b : int
val t : int
val u : int
val x : int
val y : int
val z : int
method a : int
method b : int
method t : int
method u : int
method x : int
method y : int
method z : int
end
# val e : e = <obj>
# - : int * int * int * int * int * int * int = (1, 3, 2, 2, 3, 5, 7)
# class c :
int ->
int -> object val x : int val y : int method x : int method y : int end
# class d :
int ->
int -> object val x : int val y : int method x : int method y : int end
# - : int * int = (1, 2)
# - : int * int = (1, 2)
# class ['a] c : 'a -> object end
# - : 'a -> 'a c = <fun>
# * * * * * * * * * * * * * * * * * * * * * module M : sig class c : unit -> object method xc : int end end
# class d : unit -> object val x : int method xc : int method xd : int end
# - : int * int = (1, 2)
# Characters 7-156:
......virtual ['a] matrix (sz, init : int * 'a) = object
val m = Array.create_matrix sz sz init
method add (mtx : 'a matrix) = (mtx#m.(0).(0) : 'a)
end..
Error: The abbreviation 'a matrix expands to type < add : 'a matrix -> 'a >
but is used with type < m : 'a array array; .. >
# class c : unit -> object method m : c end
# - : c = <obj>
# module M : sig class c : unit -> object method m : c end end
# - : M.c = <obj>
# type uu = A of int | B of (< leq : 'a > as 'a)
# class virtual c : unit -> object ('a) method virtual m : 'a end
# module S : sig val f : (#c as 'a) -> 'a end
# Characters 12-43:
............struct
let f (x : #c) = x
end......
Error: Signature mismatch:
Modules do not match:
sig val f : (#c as 'a) -> 'a end
is not included in
sig val f : #c -> #c end
Values do not match:
val f : (#c as 'a) -> 'a
is not included in
val f : #c -> #c
# Characters 32-55:
module M = struct type t = int class t () = object end end;;
^^^^^^^^^^^^^^^^^^^^^^^
Error: Multiple definition of the type name t.
Names must be unique in a given structure or signature.
# - : < m : (< m : 'a > as 'b) -> 'b as 'a; .. > -> 'b = <fun>
# Characters 10-39:
fun x -> (x : int -> bool :> 'a -> 'a);;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Type int -> bool is not a subtype of int -> int
# Characters 9-40:
fun x -> (x : int -> bool :> int -> int);;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Type int -> bool is not a subtype of int -> int
# - : < > -> < > = <fun>
# - : < .. > -> < > = <fun>
# val x : '_a list ref = {contents = []}
# module F : functor (X : sig end) -> sig type t = int end
# - : < m : int > list ref = {contents = []}
# type 'a t
# Characters 9-19:
fun (x : 'a t as 'a) -> ();;
^^^^^^^^^^
Error: This alias is bound to type 'a t but is used as an instance of type 'a
The type variable 'a occurs inside 'a t
# Characters 19-20:
fun (x : 'a t) -> (x : 'a); ();;
^
Error: This expression has type 'a t but an expression was expected of type
'a
The type variable 'a occurs inside 'a t
# type 'a t = < x : 'a >
# - : ('a t as 'a) -> unit = <fun>
# Characters 18-26:
fun (x : 'a t) -> (x : 'a); ();;
^^^^^^^^
Warning 10: this expression should have type unit.
- : ('a t as 'a) t -> unit = <fun>
# class ['a] c :
unit ->
object constraint 'a = (< .. > as 'b) -> unit method m : 'b -> unit end
# class ['a] c :
unit ->
object constraint 'a = unit -> (< .. > as 'b) method m : 'a -> 'b end
# class c : unit -> object method private m : int method n : int end
# class d :
unit -> object method private m : int method n : int method o : int end
# - : int * int = (1, 1)
# class c : unit -> object method m : int end
# - : int = 15
# - : int = 16
# - : int = 17
# - : int * int * int = (18, 19, 20)
# - : int * int * int * int * int = (21, 22, 23, 33, 33)
# - : int * int * int * int * int = (24, 25, 26, 33, 33)
#