Permalink
Browse files

merge branches/record-disambiguation

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13112 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
2 parents 705510e + 17fc404 commit c8273a179cb0bc835924eeca522922a1769d9d54 Jacques Garrigue committed Dec 6, 2012
View
@@ -752,7 +752,7 @@ compilation in any way (even if it is marked). If a warning is enabled,
.IP
The default setting is
-.BR \-w\ +a\-4\-6\-9\-27\-29\-32..39 .
+.BR \-w\ +a\-4\-6\-9\-27\-29\-32..39\-41 .
Note that warnings
.BR 5 \ and \ 10
are not always triggered, depending on the internals of the type checker.
@@ -12,9 +12,9 @@
default:
@for file in *.ml; do \
- $(OCAML) < $$file 2>&1 | grep -v '^ OCaml version' > $$file.result; \
+ $(OCAML) $(TOPFLAGS) < $$file 2>&1 | grep -v '^ OCaml version' > $$file.result; \
if [ -f $$file.principal.reference ]; then \
- $(OCAML) -principal < $$file 2>&1 | grep -v '^ OCaml version' > $$file.principal.result; \
+ $(OCAML) $(TOPFLAGS) -principal < $$file 2>&1 | grep -v '^ OCaml version' > $$file.principal.result; \
fi; \
done
@for file in *.reference; do \
@@ -75,8 +75,7 @@ Error: This pattern matches values of type ([? `A ] as 'a) * bool t
# Characters 87-88:
let f = function A -> 1 | B -> 2
^
-Error: This pattern matches values of type b
- but a pattern was expected which matches values of type a
+Error: The variant type a has no constructor B
# type _ t = Int : int t
# val ky : 'a -> 'a -> 'a = <fun>
# val test : 'a t -> 'a = <fun>
@@ -20,10 +20,16 @@ let f {M.x; y} = x+y;;
let r = {M.x=1; y=2};;
let z = f r;;
-module M = struct
- type t = {x: int; y: int}
- type u = {y: bool}
-end;;
-(* path abbreviation is syntactic *)
-let f {M.x; y} = x+y;; (* fails *)
-let r = {M.x=1; y=2};; (* fails *)
+(* messages *)
+type foo = { mutable y:int };;
+let f (r: int) = r.y <- 3;;
+
+(* bugs *)
+type foo = { y: int; z: int };;
+type bar = { x: int };;
+let f (r: bar) = ({ r with z = 3 } : foo)
+
+type foo = { x: int };;
+let r : foo = { ZZZ.x = 2 };;
+
+(ZZZ.X : int option);;
@@ -0,0 +1,50 @@
+
+# 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
+#
@@ -3,16 +3,16 @@
# Characters 5-6:
{x=3;z=2};;
^
-Error: Unbound record field label z
+Error: Unbound record field z
# Characters 9-10:
fun {x=3;z=2} -> ();;
^
-Error: Unbound record field label z
+Error: Unbound record field z
# Characters 26-34:
{x=3; contents=2};;
^^^^^^^^
-Error: The record field label Pervasives.contents belongs to the type
- 'a ref but is mixed here with labels of type t
+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};;
@@ -26,15 +26,25 @@ Error: Cannot assign field u of the private type u
# val f : M.t -> int = <fun>
# val r : M.t = {M.x = 1; y = 2}
# val z : int = 3
-# module M : sig type t = { x : int; y : int; } type u = { y : bool; } end
-# Characters 43-51:
- let f {M.x; y} = x+y;; (* fails *)
- ^^^^^^^^
-Error: This pattern matches values of type M.u
- but a pattern was expected which matches values of type M.t
-# Characters 16-17:
- let r = {M.x=1; y=2};; (* fails *)
- ^
-Error: The record field label M.y belongs to the type M.u
- but is mixed here with labels of type M.t
+# 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
#
@@ -0,0 +1,16 @@
+#########################################################################
+# #
+# OCaml #
+# #
+# Xavier Clerc, SED, INRIA Rocquencourt #
+# #
+# Copyright 2010 Institut National de Recherche en Informatique et #
+# en Automatique. All rights reserved. This file is distributed #
+# under the terms of the Q Public License version 1.0. #
+# #
+#########################################################################
+
+BASEDIR=../..
+include $(BASEDIR)/makefiles/Makefile.toplevel
+include $(BASEDIR)/makefiles/Makefile.common
+TOPFLAGS = -w A
@@ -0,0 +1,128 @@
+(* Use type information *)
+module M1 = struct
+ type t = {x: int; y: int}
+ type u = {x: bool; y: bool}
+end;;
+
+module OK = struct
+ open M1
+ let f1 (r:t) = r.x (* ok *)
+ let f2 r = ignore (r:t); r.x (* non principal *)
+
+ let f3 (r: t) =
+ match r with {x; y} -> y + y (* ok *)
+end;;
+
+module F1 = struct
+ open M1
+ let f r = match r with {x; y} -> y + y
+end;; (* fails *)
+
+module F2 = struct
+ open M1
+ let f r =
+ ignore (r: t);
+ match r with
+ {x; y} -> y + y
+end;; (* fails for -principal *)
+
+(* Use type information with modules*)
+module M = struct
+ type t = {x:int}
+ type u = {x:bool}
+end;;
+let f (r:M.t) = r.M.x;; (* ok *)
+let f (r:M.t) = r.x;; (* warning *)
+
+module M = struct
+ type t = {x: int; y: int}
+end;;
+module N = struct
+ type u = {x: bool; y: bool}
+end;;
+module OK = struct
+ open M
+ open N
+ let f (r:M.t) = r.x
+end;;
+
+module M = struct
+ type t = {x:int}
+ module N = struct type s = t = {x:int} end
+ type u = {x:bool}
+end;;
+module OK = struct
+ open M.N
+ let f (r:M.t) = r.x
+end;;
+
+(* Use field information *)
+module M = struct
+ type u = {x:bool;y:int;z:char}
+ type t = {x:int;y:bool}
+end;;
+module OK = struct
+ open M
+ let f {x;z} = x,z
+end;; (* ok *)
+module F3 = struct
+ open M
+ let r = {x=true;z='z'}
+end;; (* fail for missing label *)
+
+module OK = struct
+ type u = {x:int;y:bool}
+ type t = {x:bool;y:int;z:char}
+ let r = {x=3; y=true}
+end;; (* ok *)
+
+(* Corner cases *)
+
+module F4 = struct
+ type foo = {x:int; y:int}
+ type bar = {x:int}
+ let b : bar = {x=3; y=4}
+end;; (* fail but don't warn *)
+
+module M = struct type foo = {x:int;y:int} end;;
+module N = struct type bar = {x:int;y:int} end;;
+let r = { M.x = 3; N.y = 4; };; (* error: different definitions *)
+
+module MN = struct include M include N end
+module NM = struct include N include M end;;
+let r = {MN.x = 3; NM.y = 4};; (* error: type would change with order *)
+
+(* Lpw25 *)
+
+module M = struct
+ type foo = { x: int; y: int }
+ type bar = { x:int; y: int; z: int}
+end;;
+module F5 = struct
+ open M
+ let f r = ignore (r: foo); {r with x = 2; z = 3}
+end;;
+module M = struct
+ include M
+ type other = { a: int; b: int }
+end;;
+module F6 = struct
+ open M
+ let f r = ignore (r: foo); { r with x = 3; a = 4 }
+end;;
+module F7 = struct
+ open M
+ let r = {x=1; y=2}
+ let r: other = {x=1; y=2}
+end;;
+
+module A = struct type t = {x: int} end
+module B = struct type t = {x: int} end;;
+let f (r : B.t) = r.A.x;; (* fail *)
+
+(* Spellchecking *)
+
+module F8 = struct
+ type t = {x:int; yyy:int}
+ let a : t = {x=1;yyz=2}
+end;;
Oops, something went wrong.

0 comments on commit c8273a1

Please sign in to comment.