Commits

garrigue  committed c628c24

Fix (type a) scope, was broken by gadt addition

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12599f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

  • Participants
  • Parent commits ee971c5

Comments (0)

Files changed (5)

File testsuite/tests/typing-typeparam/Makefile

-#MODULES=
 BASEDIR=../..
-MAIN_MODULE=newtype
-ADD_COMPFLAGS=-w a
-
-include $(BASEDIR)/makefiles/Makefile.one
+include $(BASEDIR)/makefiles/Makefile.toplevel
 include $(BASEDIR)/makefiles/Makefile.common
+

File testsuite/tests/typing-typeparam/newtype.ml

 let property (type t) () =
   let module M = struct exception E of t end in
   (fun x -> M.E x), (function M.E x -> Some x | _ -> None)
+;;
 
 let () =
   let (int_inj, int_proj) = property () in
   Printf.printf "%b\n%!" (int_proj s = None);
   Printf.printf "%b\n%!" (string_proj i = None);
   Printf.printf "%b\n%!" (string_proj s = None)
-
-
-
+;;
 
 let sort_uniq (type s) cmp l =
   let module S = Set.Make(struct type t = s let compare = cmp end) in
   S.elements (List.fold_right S.add l S.empty)
+;;
 
 let () =
   print_endline (String.concat "," (sort_uniq compare [ "abc"; "xyz"; "abc" ]))
+;;
 
-
+let f x (type a) (y : a) = (x = y);; (* Fails *)
+class ['a] c = object (self)
+  method m : 'a -> 'a = fun x -> x
+  method n : 'a -> 'a = fun (type g) (x:g) -> self#m x
+end;; (* Fails *)

File testsuite/tests/typing-typeparam/newtype.ml.reference

+
+#       val property : unit -> ('a -> exn) * (exn -> 'a option) = <fun>
+#                         false
+true
+true
+false
+#         val sort_uniq : ('a -> 'a -> int) -> 'a list -> 'a list = <fun>
+#       abc,xyz
+#   Characters 33-34:
+  let f x (type a) (y : a) = (x = y);; (* Fails *)
+                                  ^
+Error: This expression has type a but an expression was expected of type a
+       The type constructor a would escape its scope
+#       Characters 117-118:
+    method n : 'a -> 'a = fun (type g) (x:g) -> self#m x
+                                                       ^
+Error: This expression has type g but an expression was expected of type g
+       The type constructor g would escape its scope
+# 

File testsuite/tests/typing-typeparam/newtype.reference

-false
-true
-true
-false
-abc,xyz

File typing/typecore.ml

       in
       re { exp with exp_desc = Texp_poly(exp, cty) }
   | Pexp_newtype(name, sbody) ->
+      let ty = newvar () in
+      (* remember original level *)
+      begin_def ();
       (* Create a fake abstract type declaration for name. *)
       let level = get_current_level () in
       let decl = {
         type_loc = loc;
       }
       in
-      let ty = newvar () in
-      (* remember original level *)
-      begin_def ();
       Ident.set_current_time ty.level;
       let (id, new_env) = Env.enter_type name decl env in
       Ctype.init_def(Ident.current_time());