[Mono-dev] Infinite recursion (mcs 1.2.3.1 vs Microsoft csc)

marek.safar at seznam.cz marek.safar at seznam.cz
Sun May 13 05:38:03 EDT 2007


Hello Dan,

Please fill a bug report at http://bugzilla.ximian.com.

Thanks,
Marek
 
> 
> If I compile the OnUpdate method with mcs, I get an infinite recursion due to
> the compiler generating a callvirt instead of call.
> The Microsoft compiler doesn't have the same issue.
> Note that if I just have a virtual method Print1, both mcs and csc generate the
> same code (call       instance void Test1.TestItem1::Print()).
> 
> Here's the ildasm output for the TestItem2::add_OnUpdate (mcs vs csc):
> 
> mcs:
> .method public hidebysig specialname virtual 
>         instance void  add_OnUpdate(class Test1.TestDelegate1 'value') cil
> managed
> {
>   // Code size       18 (0x12)
>   .maxstack  8
>   IL_0000:  ldstr      "OnUpdate add 2"
>   IL_0005:  call       void [mscorlib]System.Console::WriteLine(string)
>   IL_000a:  ldarg.0
>   IL_000b:  ldarg.1
>   IL_000c:  callvirt   instance void Test1.TestItem1::add_OnUpdate(class
> Test1.TestDelegate1)
>   IL_0011:  ret
> } // end of method TestItem2::add_OnUpdate
> 
> csc:
> .method public hidebysig specialname virtual 
>         instance void  add_OnUpdate(class Test1.TestDelegate1 'value') cil
> managed
> {
>   // Code size       18 (0x12)
>   .maxstack  2
>   IL_0000:  ldstr      "OnUpdate add 2"
>   IL_0005:  call       void [mscorlib]System.Console::WriteLine(string)
>   IL_000a:  ldarg.0
>   IL_000b:  ldarg.1
>   IL_000c:  call       instance void Test1.TestItem1::add_OnUpdate(class
> Test1.TestDelegate1)
>   IL_0011:  ret
> } // end of method TestItem2::add_OnUpdate
> 
> and the test code:
> 
> namespace Test1
> {    
>     public delegate void TestDelegate1(TestItem item);
>     
>     public interface TestItem
>     {        
>     event TestDelegate1 OnUpdate;       
>     }
>     
>     public class TestItem1 : TestItem
>     {   
>         private TestDelegate1 delegates1;
>         
>         public TestItem1()            
>         {
>         }
>         
>         public virtual void Print()
>         {
>             System.Console.WriteLine("Print 1");    
>         }
> 
>         public virtual event TestDelegate1 OnUpdate
>         {
>             add
>             {
>                 System.Console.WriteLine("OnUpdate add 1");
>                 
>                 delegates1 += value;
>             }
>             remove
>             {
>                 System.Console.WriteLine("OnUpdate remove 2");
>                 delegates1 -= value;
>             }
>         }
>         
>     }
>     
>     public class TestItem2 : TestItem1
>     {        
>         public TestItem2()
>             : base()
>         {
>         }
>         
>         public override void Print()
>     {
>         System.Console.WriteLine("Print 2");    
>         base.Print();    
>         }
> 
>         public override event TestDelegate1 OnUpdate
>         {
>             add
>             {
>                 System.Console.WriteLine("OnUpdate add 2");
>                 base.OnUpdate += value;                
>             }
>             remove
>             {
>                 System.Console.WriteLine("OnUpdate remove 2");
>                 base.OnUpdate -= value;                
>             }
>         }
>     }
> }
> 
> Thanks,
> 
> Dan
>  
> ---------------------------------
> Bored stiff? Loosen up...
> Download and play hundreds of games for free on Yahoo! Games.
> 
> 



More information about the Mono-devel-list mailing list