[svn] r6086: nemerle/trunk/ncc: testsuite/negative/tc.n typing/TyVarEnv.n

malekith svnadmin at nemerle.org
Tue Jan 24 16:06:50 CET 2006


Log:
Make shadowing a type parameter a hard error. Resolves #585.

Author: malekith
Date: Tue Jan 24 16:06:49 2006
New Revision: 6086

Modified:
   nemerle/trunk/ncc/testsuite/negative/tc.n
   nemerle/trunk/ncc/typing/TyVarEnv.n

Modified: nemerle/trunk/ncc/testsuite/negative/tc.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/negative/tc.n	(original)
+++ nemerle/trunk/ncc/testsuite/negative/tc.n	Tue Jan 24 16:06:49 2006
@@ -15,7 +15,8 @@
   static y : 'a;        // OK
   m1 (_ : 'a) : void {}         // OK
   static m2 (_ : 'a) : void {}   // OK
-  static m3['a] (_ : 'a) : void {}   // OK
+  static m3['b] (_ : 'b) : void {}   // OK
+  static m4['a] (_ : 'a) : void {}   // E: already in the scope
 
   class B {
     foo (x : 'a) : void {} // OK

Modified: nemerle/trunk/ncc/typing/TyVarEnv.n
==============================================================================
--- nemerle/trunk/ncc/typing/TyVarEnv.n	(original)
+++ nemerle/trunk/ncc/typing/TyVarEnv.n	Tue Jan 24 16:06:49 2006
@@ -364,15 +364,18 @@
                        curtc : TypeBuilder,
                        check_parms : bool) : TyVarEnv * list [StaticTyVar]
     {
-      def name_of_tv (tv) {
-        def (name, color) = tv;
+      def name_of_tv (name, color) {
         Name (name, color, null)
       }
       def loop (tv : string * int, acc) {
         def (map, the_list) = acc;
         def tv_obj = StaticTyVar (Pair.First (tv));
-        ((map : NemerleMap [Name, StaticTyVar]).Replace (name_of_tv (tv), tv_obj),
-         tv_obj :: the_list)
+        def name = name_of_tv (tv);
+        when (map.Contains (name)) {
+          Message.Error ($ "a type variable named `$name' is already in the scope");
+          Message.Hint ("you can either rename the new variable, or use the old one and remove the new one");
+        }
+        (map.Replace (name, tv_obj), tv_obj :: the_list)
       }
       def (m, l) = List.FoldLeft (tp.tyvars, (this.tyvars, []), loop);
       def tenv = TyVarEnv (m);



More information about the svn mailing list