2009-04-11 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / mini / generics.cs
index 1780be65f0381ffbdf8bda2fea6246d8c6ee6ba7..f7c8393e77fa601a0d4bdc481c9a6704905957fd 100644 (file)
@@ -240,6 +240,10 @@ class Tests {
                return 0;
        }
 
+       public static int test_0_nullable_ldflda () {
+               return GenericClass<string>.BIsAClazz == false ? 0 : 1;
+       }
+
        public struct GenericStruct<T> {
                public T t;
 
@@ -285,6 +289,15 @@ class Tests {
                {
                        return x [index];
                }
+
+        protected static T NullB = default(T);       
+        private static Nullable<bool>  _BIsA = null;
+        public static bool BIsAClazz {
+            get {
+                _BIsA = false;
+                return _BIsA.Value;
+            }
+        }
        }
 
        public class MRO : MarshalByRefObject {
@@ -319,7 +332,7 @@ class Tests {
 
     public static int test_0_generic_virtual_call_on_vtype_unbox () {
                object o = new Object ();
-        IMyHandler h = new Handler(o);
+        IFoo h = new Handler(o);
 
         if (h.Bar<object> () != o)
                        return 1;
@@ -383,6 +396,39 @@ class Tests {
                return the_type == typeof (string) ? 0 : 1;
        }
 
+       public static int test_0_throw_dead_this () {
+        new Foo<string> ("").throw_dead_this ();
+               return 0;
+       }
+
+       public static int test_0_generic_virtual_on_interfaces () {
+               Foo<string>.count1 = 0;
+               Foo<string>.count2 = 0;
+               Foo<string>.count3 = 0;
+
+               IFoo f = new Foo<string> ("");
+               for (int i = 0; i < 1000; ++i) {
+                       f.Bar <int> ();
+                       f.Bar <string> ();
+                       f.NonGeneric ();
+               }
+
+               if (Foo<string>.count1 != 1000)
+                       return 1;
+               if (Foo<string>.count2 != 1000)
+                       return 2;
+               if (Foo<string>.count3 != 1000)
+                       return 3;
+
+               VirtualInterfaceCallFromGenericMethod<long> (f);
+
+               return 0;
+       }
+
+       public static void VirtualInterfaceCallFromGenericMethod <T> (IFoo f) {
+               f.Bar <T> ();
+       }
+
        public static Type the_type;
 
        public void ldvirtftn<T> () {
@@ -396,7 +442,12 @@ class Tests {
                the_type = typeof (T);
        }
 
-       public class Foo<T1>
+       public interface IFoo {
+               void NonGeneric ();
+               object Bar<T>();
+       }
+
+       public class Foo<T1> : IFoo
        {
                public Foo(T1 t1)
                {
@@ -419,6 +470,14 @@ class Tests {
                        }
                }
 
+               public void throw_dead_this () {
+                       try {
+                               new SomeClass().ThrowAnException();
+                       }
+                       catch {
+                       }
+               }
+
                public T1 get_default () {
                        return default (T1);
                }
@@ -433,19 +492,37 @@ class Tests {
                        GenericEvent (this);
                }
 
-       }
+               public static int count1, count2, count3;
 
-       public interface IMyHandler {
-               object Bar<T>();
+               public void NonGeneric () {
+                       count3 ++;
+               }
+
+               public object Bar <T> () {
+                       if (typeof (T) == typeof (int))
+                               count1 ++;
+                       else if (typeof (T) == typeof (string))
+                               count2 ++;
+                       return null;
+               }
        }
 
-       struct Handler : IMyHandler {
+       public class SomeClass {
+               public void ThrowAnException() {
+                       throw new Exception ("Something went wrong");
+               }
+       }               
+
+       struct Handler : IFoo {
                object o;
 
                public Handler(object o) {
                        this.o = o;
                }
 
+               public void NonGeneric () {
+               }
+
                public object Bar<T>() {
                        return o;
                }