[svn] r7803: nemerle/trunk/ncc: testsuite/negative/where-constraints4.n testsuite/positive/gen-special.n t...

divan svnadmin at nemerle.org
Tue Oct 9 19:24:09 CEST 2007


Log:
Fix new() constraint:
1) it implies not abstract
2) it can be implied by other constraints

Author: divan
Date: Tue Oct  9 19:24:05 2007
New Revision: 7803

Added:
   nemerle/trunk/ncc/testsuite/negative/where-constraints4.n
Modified:
   nemerle/trunk/ncc/testsuite/positive/gen-special.n
   nemerle/trunk/ncc/typing/StaticTyVar.n

Added: nemerle/trunk/ncc/testsuite/negative/where-constraints4.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/ncc/testsuite/negative/where-constraints4.n	Tue Oct  9 19:24:05 2007
@@ -0,0 +1,15 @@
+abstract class A
+{
+  public this () { //it's ok, it can be called as some class's base ()
+  }
+}
+
+module Go
+{
+  f[T] (_ : T) : void where T : new () {
+    _ = T ();
+  }
+  Main () : void {
+    f (null : A); // E: must have a public parameterless constructor and must not be abstract
+  }
+}

Modified: nemerle/trunk/ncc/testsuite/positive/gen-special.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/gen-special.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/gen-special.n	Tue Oct  9 19:24:05 2007
@@ -79,6 +79,20 @@
   f : C ['a];
 }
 
+namespace NEW
+{
+  class A 
+  {
+  }
+  class B[T] where T : A
+  {
+    public static f[Q] () : void where Q : new () {
+    }
+    public q () : void {
+      _ = f.[T] (); //T has A constraint so it's "new ()"
+    }
+  }
+}
 
 assert (A().foo ("a") == null);
 assert (B().foo (0) == 0);

Modified: nemerle/trunk/ncc/typing/StaticTyVar.n
==============================================================================
--- nemerle/trunk/ncc/typing/StaticTyVar.n	(original)
+++ nemerle/trunk/ncc/typing/StaticTyVar.n	Tue Oct  9 19:24:05 2007
@@ -268,7 +268,8 @@
     /// Check if [tv] fullfills [this]'s constraints.
     public CheckConstraints (tv : TyVar, thing : object) : void
     {
-      def has_default_ctor (t) {
+      def default_ctorable (t) {
+        | MType.Class (ti, _) when ti.IsAbstract => false
         | MType.Class (ti, _) =>
           ! t.CanBeNull || // value types always have this ctor
           ti.LookupMember (".ctor").Exists (fun (_) {
@@ -280,6 +281,7 @@
         | MType.TyVarRef (s) =>
           s.SpecialConstraints %&& 
           GenericParameterAttributes.DefaultConstructorConstraint
+          || List.Exists (s.Constraints, default_ctorable)
         | _ => false
       }
 
@@ -312,10 +314,11 @@
       
       when (SpecialConstraints %&& 
             GenericParameterAttributes.DefaultConstructorConstraint &&
-            ! has_default_ctor (t))
+            ! default_ctorable (t))
         // cs310
         Message.Error ($ "the type `$t' must have a public parameterless "
-                         "constructor in order to use it as type parameter "
+                         "constructor and must not be abstract in order "
+                         "to use it as type parameter "
                          "`$(Name)' in $thing");
     }
     



More information about the svn mailing list