[svn] r7044: nemerle/trunk/ncc: external/InternalTypes.n testsuite/positive/array.n typing/Solver.n

malekith svnadmin at nemerle.org
Mon Dec 4 17:50:03 CET 2006


Log:
Treat arrays in a more liberal way in type sums. Resolves #717.

Author: malekith
Date: Mon Dec  4 17:50:02 2006
New Revision: 7044

Modified:
   nemerle/trunk/ncc/external/InternalTypes.n
   nemerle/trunk/ncc/testsuite/positive/array.n
   nemerle/trunk/ncc/typing/Solver.n

Modified: nemerle/trunk/ncc/external/InternalTypes.n
==============================================================================
--- nemerle/trunk/ncc/external/InternalTypes.n	(original)
+++ nemerle/trunk/ncc/external/InternalTypes.n	Mon Dec  4 17:50:02 2006
@@ -424,6 +424,8 @@
   public mutable AssemblyCultureAttribute_tc : TypeInfo;  
   public mutable Nemerle_list_tc : TypeInfo;
   public mutable Nemerle_option_tc : TypeInfo;
+  public mutable IList_tc : TypeInfo;
+  public mutable ICollection_tc : TypeInfo;
   public mutable IEnumerable_tc : TypeInfo;
   public mutable IEnumerator_tc : TypeInfo;
   public mutable Generic_IEnumerable_tc : TypeInfo;
@@ -592,6 +594,8 @@
     ValueType_tc = lookup ("System.ValueType"); ValueType = MType.Class (ValueType_tc, []);
     IEnumerable_tc = lookup ("System.Collections.IEnumerable");
     IEnumerator_tc = lookup ("System.Collections.IEnumerator");
+    IList_tc = lookup ("System.Collections.IList");
+    ICollection_tc = lookup ("System.Collections.ICollection");
     Generic_IEnumerable_tc = lookup ("System.Collections.Generic.IEnumerable");
     Generic_IEnumerator_tc = lookup ("System.Collections.Generic.IEnumerator");
     Generic_IList_tc = lookup ("System.Collections.Generic.IList");

Modified: nemerle/trunk/ncc/testsuite/positive/array.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/array.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/array.n	Mon Dec  4 17:50:02 2006
@@ -103,6 +103,27 @@
     def a1 = array["qq", "aa"];
     def a2 = a1 :> array[object];
     System.Console.WriteLine(a2.GetType());
+
+    // bug #717
+    {
+      def seq : System.Collections.Generic.IEnumerable[int] = array[1,2,3];
+      def seq2 : System.Collections.IEnumerable = array[1,2,3];
+
+      def f(seq)
+      {
+        | _ is array[int] => System.Console.WriteLine("Is array!")
+        | _ => System.Console.WriteLine("Is NOT array.")
+      }
+
+      def f2(seq)
+      {
+        | _ is array[int] => System.Console.WriteLine("Is array!")
+        | _ => System.Console.WriteLine("Is NOT array.")
+      }
+
+      f (seq);
+      f2 (seq2);
+    }
   }
 }
 
@@ -126,5 +147,7 @@
 data[2] = 42
 data[3] = 42
 System.String[]
+Is array!
+Is array!
 END-OUTPUT
 */

Modified: nemerle/trunk/ncc/typing/Solver.n
==============================================================================
--- nemerle/trunk/ncc/typing/Solver.n	(original)
+++ nemerle/trunk/ncc/typing/Solver.n	Mon Dec  4 17:50:02 2006
@@ -330,9 +330,19 @@
         mutable seen_object = allow_fake;
         mutable seen_value_type = allow_fake;
         mutable seen_non_class_type = false;
+        mutable seen_class_type = false;
+        mutable seen_array_type = false;
+        
+        def add_supertypes (s) {
+          if (supertypes == null)
+            supertypes = s
+          else
+            supertypes = supertypes.Intersect (s);
+        }
 
         foreach (t in lst) {
           | MType.Class (tc, _) =>
+            seen_class_type = true;
             when (tc.Equals (InternalType.Object_tc))
               seen_object = true;
             when (tc.Equals (InternalType.ValueType_tc))
@@ -346,16 +356,25 @@
                       s.Replace (tc)
                   }
                 });
-            if (supertypes == null)
-              supertypes = s
-            else
-              supertypes = supertypes.Intersect (s);
+            add_supertypes (s)
+
+          | Array =>
+            seen_array_type = true;
+            add_supertypes (
+               Set.Singleton (InternalType.Generic_ICollection_tc).
+                   Add (InternalType.Generic_IList_tc).
+                   Add (InternalType.Generic_IEnumerable_tc).
+                   Add (InternalType.IEnumerable_tc).
+                   Add (InternalType.IList_tc).
+                   Add (InternalType.ICollection_tc).
+                   Add (InternalType.Object_tc)
+                   )
 
           | _ =>
             seen_non_class_type = true;
         }
 
-        when (seen_non_class_type)
+        when (seen_non_class_type || (seen_array_type && !seen_class_type))
           if (seen_object)
             Nemerle.Imperative.Return (InternalType.Object)
           else



More information about the svn mailing list