diff options
author | Aleksey Kliger <alklig@microsoft.com> | 2017-11-16 01:43:18 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2017-11-16 11:15:47 +0300 |
commit | 8b7df777bbebd2d4712120739bb7958f96bda876 (patch) | |
tree | 98d0e9349f2126c6dc70eeba289f19c27e413e4f /mcs/class/corlib | |
parent | bcaca2dbafcfaad7096ff9fe64bcf81e4d9bddb5 (diff) |
[test] Regression test for 60238
Diffstat (limited to 'mcs/class/corlib')
-rw-r--r-- | mcs/class/corlib/Test/System.Reflection.Emit/ModuleBuilderTest.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/mcs/class/corlib/Test/System.Reflection.Emit/ModuleBuilderTest.cs b/mcs/class/corlib/Test/System.Reflection.Emit/ModuleBuilderTest.cs index 3bf8fe8246e..e2574908f45 100644 --- a/mcs/class/corlib/Test/System.Reflection.Emit/ModuleBuilderTest.cs +++ b/mcs/class/corlib/Test/System.Reflection.Emit/ModuleBuilderTest.cs @@ -298,6 +298,59 @@ namespace MonoTests.System.Reflection.Emit // (they do not provide an implementation of ToString). } + [Test] + public void GetArrayMethodMultipleCallsTest () + { + AssemblyBuilder ab = genAssembly (); + ModuleBuilder modb = ab.DefineDynamicModule ("foo.dll", "foo.dll"); + + TypeBuilder tb = modb.DefineType ("TestType"); + var int2D = typeof (int[,]); + var mb = tb.DefineMethod ("TestMeth", MethodAttributes.Static | MethodAttributes.Public, + typeof(int), new Type[] { int2D }); + var ilg = mb.GetILGenerator (); + + // static int TestMeth(int[,] a) + // { + // int x; + // x = a.Get(0,0); + // return a.Get(0,1) + x; + // } + // + + var x = ilg.DeclareLocal (typeof (int)); + + ilg.Emit (OpCodes.Ldarg_0); + ilg.Emit (OpCodes.Ldc_I4_0); + ilg.Emit (OpCodes.Ldc_I4_0); + var arrmi = modb.GetArrayMethod (int2D, "Get", + CallingConventions.Standard | CallingConventions.HasThis, + typeof(int), + new Type[] { typeof(int), typeof(int) }); + ilg.Emit (OpCodes.Call, arrmi); + ilg.Emit (OpCodes.Stloc, x); + var arrmi2 = modb.GetArrayMethod (int2D, "Get", + CallingConventions.Standard | CallingConventions.HasThis, + typeof(int), + new Type[] { typeof(int), typeof(int) }); + ilg.Emit (OpCodes.Ldarg_0); + ilg.Emit (OpCodes.Ldc_I4_0); + ilg.Emit (OpCodes.Ldc_I4_1); + ilg.Emit (OpCodes.Call, arrmi2); + ilg.Emit (OpCodes.Ldloc, x); + ilg.Emit (OpCodes.Add); + ilg.Emit (OpCodes.Ret); + Assert.AreNotSame (arrmi, arrmi2); // fresh MonoArrayMethods each time + + var t = tb.CreateType (); + Assert.IsNotNull (t); + var a = new int[,] { { 5, 7 }, { 11, 19 } }; + var mi = t.GetMethod ("TestMeth"); + Assert.IsNotNull (t); + var o = mi.Invoke (null, new object[] { a }); + Assert.AreEqual (12, (int)o); + } + private static void AssertArrayEqualsSorted (Array o1, Array o2) { Array s1 = (Array) o1.Clone (); |