[svn] r7100: nemerle/trunk/ncc: CompilationOptions.n passes.n testsuite/positive/generic-nongeneric.n typi...

nazgul svnadmin at nemerle.org
Sat Dec 16 12:27:35 CET 2006


Log:
Add warning for free generic arguments survived after Typer. Based on patch by Evin Robertson.

Author: nazgul
Date: Sat Dec 16 12:27:31 2006
New Revision: 7100

Modified:
   nemerle/trunk/ncc/CompilationOptions.n
   nemerle/trunk/ncc/passes.n
   nemerle/trunk/ncc/testsuite/positive/generic-nongeneric.n
   nemerle/trunk/ncc/typing/Typer2.n

Modified: nemerle/trunk/ncc/CompilationOptions.n
==============================================================================
--- nemerle/trunk/ncc/CompilationOptions.n	(original)
+++ nemerle/trunk/ncc/CompilationOptions.n	Sat Dec 16 12:27:31 2006
@@ -410,9 +410,9 @@
                                  handler = fun (x) {
                                    Warnings.Level =
                                      match (x) {
-                                       | "1" => 1 | "2" => 2 | "3" => 3 | "4" => 4
+                                       | "1" => 1 | "2" => 2 | "3" => 3 | "4" => 4 | "5" => 5
                                        | _ =>
-                                         Message.Error (x + " is not a valid warning level (must be 0-4)");
+                                         Message.Error (x + " is not a valid warning level (must be 0-5)");
                                          -1
                                      }
                                  }),
@@ -444,7 +444,7 @@
                                      }
                                      catch {
                                        | _ =>
-                                         Message.Error (str + " is not a valid warning number format")
+                                         Message.Error (Location.Default, str + " is not a valid warning number format")
                                      }
                                    }
                                  }),
@@ -737,7 +737,7 @@
              10001, 10003, 10005],
 
       // level 5
-      array [10002, 10004, 10006, 10007]  
+      array [10002, 10004, 10006, 10007, 10008]  
     ];
 
 
@@ -757,7 +757,8 @@
           (10004, "warnings about usage of bit operations on enums without correct attribute"),
           (10005, "warnings about ignoring computed values"),
           (10006, "`this' is unused, consider making method static"),
-          (10007, "`$' occurs inside string literal, which is not prefixed itself with `$'")
+          (10007, "`$' occurs inside string literal, which is not prefixed itself with `$'"),
+          (10008, "verify that generic arguments of methods and classes are inferred to some concrete types"),
         ];
 
         def sb = StringBuilder ();

Modified: nemerle/trunk/ncc/passes.n
==============================================================================
--- nemerle/trunk/ncc/passes.n	(original)
+++ nemerle/trunk/ncc/passes.n	Sat Dec 16 12:27:31 2006
@@ -183,6 +183,7 @@
     /// initialize pipelines with default values
     public this (options : CompilationOptions)
     {
+      Instance = this;
       assert (options != null);
       ParsingPipeline = MainParser.Parse;
       def scanner = ScanTypeHierarchy (this);

Modified: nemerle/trunk/ncc/testsuite/positive/generic-nongeneric.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/generic-nongeneric.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/generic-nongeneric.n	Sat Dec 16 12:27:31 2006
@@ -1,4 +1,5 @@
 using Nemerle.IO;
+using Nemerle.Collections;
 
   interface IComparab ['a] {
     CompareTo (_ : 'a) : int;
@@ -52,6 +53,43 @@
   }
 }
 
+namespace Bug805 {
+  public class X
+  {
+  }
+  
+  public class Y['t] : X
+  {
+      
+      public foo () : void {
+          def x = Hashtable (); // W: type arguments for method .* could not be inferred
+          x.Add ("aaa", null);
+          x.Add ("bbb", null);
+          when (x.Contains ("aaa"))
+            System.Console.WriteLine ("Got it");
+      }
+  }
+  
+  
+  public module A
+  {
+      public F['t](x : X) : bool
+      {
+      x is Y['t];
+      }
+  
+      public Run() : void
+      {
+          def y = Y() : Y[int];
+          def isY = A.F(y).ToString(); // W: type arguments for method .* could not be inferred
+          System.Console.WriteLine(isY);
+          System.Console.WriteLine(y);
+          y.foo ();
+      }
+  }
+   
+}
+
 
 class C {
   public this (_ : int) { }
@@ -66,8 +104,16 @@
 
 printf ("x=%s y=%s y.x=%s\n", x.GetType ().Name, y.GetType ().Name, y.x);
 
+Bug805.A.Run();
+
+
 /*
+OPTIONS: -dowarn:10008
+
 BEGIN-OUTPUT
 x=C y=C`1 y.x=a
+False
+Bug805.Y`1[System.Int32]
+Got it
 END-OUTPUT
 */

Modified: nemerle/trunk/ncc/typing/Typer2.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer2.n	(original)
+++ nemerle/trunk/ncc/typing/Typer2.n	Sat Dec 16 12:27:31 2006
@@ -753,6 +753,16 @@
       }
     }
 
+    static CheckTypeArguments(loc : Location, meth : IMember, type_parms : list[TyVar]) : void
+    {
+      when (found : {
+        foreach (typeParm in type_parms)
+          when (typeParm.IsFree)
+            found (true);
+        false      
+      })
+        Message.Warning (10008, loc, $"type arguments for $meth could not be inferred");
+    }
 
     DoWalk (ctx : Context, expr : TExpr) : TExpr
     {
@@ -815,13 +825,16 @@
           }
           
           
-        | TExpr.StaticRef (_, mem, _) =>
+        | TExpr.StaticRef (f, mem, type_parms) =>
+         //Message.Debug ($"from=$f, mem=$mem, tp=$type_parms");
           match (mem) {
             | f is IField when ctx & Context.NeedLValue != 0 =>
               MarkAsAssigned (f, expr.Location);
 
             | _ => MarkAsUsed (mem, expr.Location);
           }
+          CheckTypeArguments(expr.Location, mem, type_parms);
+          CheckTypeArguments(expr.Location, mem, f.args);
           null
           
           
@@ -941,6 +954,7 @@
 
           //Message.Debug ($"$(ctx %&& (Context.IsCalledValue | Context.IsDelegeteCtorParm)) obj=$(obj.GetType())/$obj ");
 
+          CheckTypeArguments(expr.Location, meth, type_parms);
           if (ctx %&& (Context.IsCalledValue | Context.IsDelegeteCtorParm))
             TExpr.MethodRef (Walk (obj), meth, type_parms, notvirt)
           else



More information about the svn mailing list