using System; class Tests { struct TestStruct { public int i; public TestStruct (int i) { this.i = i; } } static int Main () { return TestDriver.RunTests (typeof (Tests)); } public static int test_1_nullable_unbox () { return Unbox (1).Value; } public static int test_1_nullable_unbox_null () { return Unbox (null).HasValue ? 0 : 1; } public static int test_1_nullable_box () { return (int) Box (1); } public static int test_1_nullable_box_null () { return Box (null) == null ? 1 : 0; } public static int test_1_isinst_nullable () { object o = 1; return (o is int?) ? 1 : 0; } public static int test_1_nullable_unbox_vtype () { return Unbox (new TestStruct (1)).Value.i; } public static int test_1_nullable_unbox_null_vtype () { return Unbox (null).HasValue ? 0 : 1; } public static int test_1_nullable_box_vtype () { return ((TestStruct)(Box (new TestStruct (1)))).i; } public static int test_1_nullable_box_null_vtype () { return Box (null) == null ? 1 : 0; } public static int test_1_isinst_nullable_vtype () { object o = new TestStruct (1); return (o is TestStruct?) ? 1 : 0; } public static void stelem_any (T[] arr, T elem) { arr [0] = elem; } public static T ldelem_any (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 (); } public static int test_0_iface_call_null_bug_77442 () { ITest test = null; try { test.Foo (); } catch (NullReferenceException) { return 0; } return 1; } public struct GenericStruct { public T t; public GenericStruct (T t) { this.t = t; } } public class GenericClass { public T t; public GenericClass (T t) { this.t = t; } } public class MRO : MarshalByRefObject { public GenericStruct struct_field; public GenericClass class_field; } public static int test_0_ldfld_stfld_mro () { MRO m = new MRO (); GenericStruct s = new GenericStruct (5); // This generates stfld m.struct_field = s; // This generates ldflda if (m.struct_field.t != 5) return 1; // This generates ldfld GenericStruct s2 = m.struct_field; if (s2.t != 5) return 2; if (m.struct_field.t != 5) return 3; m.class_field = new GenericClass (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 () != o) return 1; else return 0; } public static int test_0_box_brtrue_opt_regress_81102 () { if (new Foo(5).ToString () == "null") return 0; else return 1; } public class Foo { 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; } readonly T1 m_t1; } public interface IMyHandler { object Bar(); } struct Handler : IMyHandler { object o; public Handler(object o) { this.o = o; } public object Bar() { return o; } } static object Box (T t) { return t; } static T Unbox (object o) { return (T) o; } }