2007-08-30 Jonathan Chambers <joncham@gmail.com>
[mono.git] / mono / mini / generics.2.cs
index 4e8b3db94c06bec03356dbda19ad4107a3eaaf6e..46df57531d3115802073241a1d208d0d0844f96b 100644 (file)
@@ -100,6 +100,119 @@ class Tests {
                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;
+       }
+
+    public static int test_0_generic_virtual_call_on_vtype_unbox () {
+               object o = new Object ();
+        IMyHandler h = new Handler(o);
+
+        if (h.Bar<object> () != o)
+                       return 1;
+               else
+                       return 0;
+    }
+
+       public static int test_0_box_brtrue_opt () {
+               Foo<int> f = new Foo<int> (5);
+
+               f [123] = 5;
+
+               return 0;
+       }
+
+       public static int test_0_box_brtrue_opt_regress_81102 () {
+               if (new Foo<int>(5).ToString () == "null")
+                       return 0;
+               else
+                       return 1;
+       }
+
+       public class Foo<T1>
+       {
+               public Foo(T1 t1)
+               {
+                       m_t1 = t1;
+               }
+               
+               public override string ToString()
+               {
+                       return Bar(m_t1 == null ? "null" : "null");
+               }
+
+               public String Bar (String s) {
+                       return s;
+               }
+
+               public int this [T1 key] {
+                       set {
+                               if (key == null)
+                                       throw new ArgumentNullException ("key");
+                       }
+               }
+               
+               readonly T1 m_t1;
+       }
+
+       public interface IMyHandler {
+               object Bar<T>();
+       }
+
+       struct Handler : IMyHandler {
+               object o;
+
+               public Handler(object o) {
+                       this.o = o;
+               }
+
+               public object Bar<T>() {
+                       return o;
+               }
+       }
+
        static object Box<T> (T t)
        {
                return t;