2007-03-12 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / Test / System.Reflection.Emit / DynamicMethodTest.cs
index b5f172cb7d469398da7f4a7051a336b492fe44ee..d4fa680ad31589cdc27c47aff31b3b8579a9213a 100644 (file)
@@ -260,6 +260,38 @@ namespace MonoTests.System.Reflection.Emit
                        object objRet = hello.Invoke (null, invokeArgs);
                        Assert.AreEqual (2, objRet, "#3");
                }
+
+               [Test]
+               public void Circular_Refs () {
+                       DynamicMethod m1 = new DynamicMethod("f1", typeof(int), new Type[] { typeof (int) },
+                                                                                                typeof(object));
+                       DynamicMethod m2 = new DynamicMethod("f2", typeof(int), new Type[] { typeof (int) },
+                                                                                                typeof(object));
+
+                       ILGenerator il1 = m1.GetILGenerator();
+                       ILGenerator il2 = m2.GetILGenerator();
+
+                       Label l = il1.DefineLabel ();
+                       //il1.EmitWriteLine ("f1");
+                       il1.Emit (OpCodes.Ldarg_0);
+                       il1.Emit (OpCodes.Ldc_I4_0);
+                       il1.Emit (OpCodes.Bne_Un, l);
+                       il1.Emit (OpCodes.Ldarg_0);
+                       il1.Emit (OpCodes.Ret);
+                       il1.MarkLabel (l);
+                       il1.Emit (OpCodes.Ldarg_0);
+                       il1.Emit (OpCodes.Ldc_I4_1);
+                       il1.Emit (OpCodes.Sub);
+                       il1.Emit (OpCodes.Call, m2);
+                       il1.Emit (OpCodes.Ret);
+
+                       //il2.EmitWriteLine("f2");
+                       il2.Emit(OpCodes.Ldarg_0);
+                       il2.Emit(OpCodes.Call, m1);
+                       il2.Emit(OpCodes.Ret);
+
+                       m1.Invoke(null, new object[] { 5 });
+               }
        }
 }