[svn] r6466: nemerle/trunk/ncc: testsuite/positive/tymatch.n typing/Typer-PatternTyper.n

nazgul svnadmin at nemerle.org
Mon Jul 24 00:17:11 CEST 2006


Log:
Support more types in 'is' pattern

Author: nazgul
Date: Mon Jul 24 00:17:08 2006
New Revision: 6466

Modified:
   nemerle/trunk/ncc/testsuite/positive/tymatch.n
   nemerle/trunk/ncc/typing/Typer-PatternTyper.n

Modified: nemerle/trunk/ncc/testsuite/positive/tymatch.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/tymatch.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/tymatch.n	Mon Jul 24 00:17:08 2006
@@ -33,6 +33,24 @@
   | KB { x : int; }
 }
   
+public class TypesMatch
+{
+    public Method [From, To] (x : From, f : From -> To) : To
+    {
+        match (x) {
+        | t is To => t
+        | _ => f (x)
+        }
+    }
+
+    public FunMatch (x : object) : string
+    {
+      | x is int -> string => x (5)
+      | _ => "nothing"
+    }
+}
+
+  
   public Main () : void
   {
     f (A ());
@@ -57,6 +75,25 @@
       | _ : C => printf ("oops\n"); // W: deprecated
       | _  => printf ("ok2\n");
     }
+
+
+    //def seq : System.Collections.Generic.IEnumerable[int] = array[1,2,3];
+    def seq : object = array[1,2,3];
+
+    def arr_match(seq)
+    {
+      | _ary is array[int] => System.Console.WriteLine("Is array!")
+      | _ => System.Console.WriteLine("Is NOT array.")
+    }
+
+    arr_match (seq);
+    arr_match ("aa");
+
+    def ex = TypesMatch ();
+    System.Console.WriteLine (ex.Method ("aa", x => x + "b"));
+    System.Console.WriteLine (ex.Method ("22", x => int.Parse (x)  + 1));
+    System.Console.WriteLine (ex.FunMatch (x => (x + 1).ToString()));
+    System.Console.WriteLine (ex.FunMatch (x => x + "aaa"));
   }
 }
 
@@ -68,5 +105,11 @@
 good!
 ok
 ok2
+Is array!
+Is NOT array.
+aa
+23
+6
+nothing
 END-OUTPUT
 */

Modified: nemerle/trunk/ncc/typing/Typer-PatternTyper.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer-PatternTyper.n	(original)
+++ nemerle/trunk/ncc/typing/Typer-PatternTyper.n	Mon Jul 24 00:17:08 2006
@@ -632,7 +632,14 @@
 
             match (needed_type) {
               | _ when res != null => res
-              | MType.Class as ty =>
+              | MType.Ref | MType.Void 
+              | MType.Out | MType.Intersection =>
+                ReportError (messenger,
+                             $ "invalid type in (x : type) pattern: "
+                               "$needed_type");
+                Pattern.Error ()
+                
+              | ty =>
                 def typed_pattern =
                   Pattern.HasType (pattern.loc, matched_value_type, ty);
                 match (TypePattern (needed_type, nested)) {
@@ -646,11 +653,6 @@
                                  "(here : type)");
                     Pattern.Error ()
                 }
-              | _ =>
-                ReportError (messenger,
-                             $ "invalid type in (x : type) pattern: "
-                               "$needed_type");
-                Pattern.Error ()
             }
 
 



More information about the svn mailing list