2006-06-04 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / mini / generics.2.cs
index bd6184d7e645deb83c126e8423318cd582880a1f..4b71190a817578c81d6563d7b2bbd5e398db66b2 100644 (file)
@@ -14,7 +14,7 @@ class Tests {
        {
                return TestDriver.RunTests (typeof (Tests));
        }
-       
+
        public static int test_1_nullable_unbox ()
        {
                return Unbox<int?> (1).Value;
@@ -40,7 +40,7 @@ class Tests {
                object o = 1;
                return (o is int?) ? 1 : 0;
        }
-       
+
        public static int test_1_nullable_unbox_vtype ()
        {
                return Unbox<TestStruct?> (new TestStruct (1)).Value.i;
@@ -48,7 +48,7 @@ class Tests {
 
        public static int test_1_nullable_unbox_null_vtype ()
        {
-               return Unbox<int?> (null).HasValue ? 0 : 1;
+               return Unbox<TestStruct?> (null).HasValue ? 0 : 1;
        }
 
        public static int test_1_nullable_box_vtype ()
@@ -67,6 +67,85 @@ class Tests {
                return (o is TestStruct?) ? 1 : 0;
        }
 
+       public static void stelem_any<T> (T[] arr, T elem) {
+               arr [0] = elem;
+       }
+
+       public static T ldelem_any<T> (T[] arr) {
+               return arr [0];
+       }
+
+       public static int test_1_ldelem_stelem_any_int () {
+               int[] arr = new int [3];
+               stelem_any (arr, 1);
+
+               return ldelem_any (arr);
+       }
+
+       interface ITest
+       {
+               void Foo<T> ();
+       }
+
+       public static int test_0_iface_call_null_bug_77442 () {
+               ITest test = null;
+
+               try {
+                       test.Foo<int> ();
+               }
+               catch (NullReferenceException) {
+                       return 0;
+               }
+               
+               return 1;
+       }
+
+       public struct GenericStruct<T> {
+               public T t;
+
+               public GenericStruct (T t) {
+                       this.t = t;
+               }
+       }
+
+       public class GenericClass<T> {
+               public T t;
+
+               public GenericClass (T t) {
+                       this.t = t;
+               }
+       }
+
+       public class MRO : MarshalByRefObject {
+               public GenericStruct<int> struct_field;
+               public GenericClass<int> class_field;
+       }
+
+       public static int test_0_ldfld_stfld_mro () {
+               MRO m = new MRO ();
+               GenericStruct<int> s = new GenericStruct<int> (5);
+               // This generates stfld
+               m.struct_field = s;
+
+               // This generates ldflda
+               if (m.struct_field.t != 5)
+                       return 1;
+
+               // This generates ldfld
+               GenericStruct<int> s2 = m.struct_field;
+               if (s2.t != 5)
+                       return 2;
+
+               if (m.struct_field.t != 5)
+                       return 3;
+
+               m.class_field = new GenericClass<int> (5);
+               if (m.class_field.t != 5)
+                       return 4;
+
+               return 0;
+       }
+
        static object Box<T> (T t)
        {
                return t;