[Mono-bugs] [Bug 78786][Nor] New - Compiler crash on anonymous methods stored in Dictionary.

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Jul 7 06:13:34 EDT 2006

Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by ohh at scisoft.dk.


--- shadow/78786	2006-07-07 06:13:34.000000000 -0400
+++ shadow/78786.tmp.7243	2006-07-07 06:13:34.000000000 -0400
@@ -0,0 +1,73 @@
+Bug#: 78786
+Product: Mono: Compilers
+Version: 1.1
+OS: GNU/Linux [Other]
+OS Details: Fedora Core 2
+Status: NEW   
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: ohh at scisoft.dk               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+Summary: Compiler crash on anonymous methods stored in Dictionary.
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+There seems to be a bug when compiling methods containing definitions of
+anonymous methods. When declaring a delegate and storing the value into a
+Dictionary-object for later use, the compiler chokes. 
+Steps to reproduce the problem:
+Save the following code-snippet as Test.cs:
+using System.Collections.Generic;
+public class Test {
+        public delegate int TestDel (int a);
+        public static void Main (string[] args) {
+                Dictionary<string, TestDel> dict = new Dictionary<string,
+TestDel> ();
+                dict["a"] = delegate (int b) {
+                        return b;
+                };
+                System.Console.WriteLine (dict["a"] (2));
+        }
+Compile the program with
+$ gmcs Test.cs
+Actual Results:
+The compiler dies with:
+Test.cs(10,4): warning CS0162: Unreachable code detected
+In type: Test
+Unhandled Exception: System.InvalidOperationException: Method
+'Test.<#AnonymousMethod>0' does not have a method body.
+  at System.Reflection.Emit.MethodBuilder.fixup () [0x00000]
+  at System.Reflection.Emit.TypeBuilder.CreateType () [0x00000]
+  at Mono.CSharp.TypeContainer.CloseType () [0x00000]
+Expected Results:
+The compiler should compile the program cleanly, and when run with "mono
+Test.exe" the value "2" should be output.
+How often does this happen? 
+Every time.
+Additional Information:
+The code works as intended on .NET 2.0 (Windows). The problem is found in
+1.1.15 but still remains in 1.1.16.
+Interessetingly the compiler does now die, if the delegate is stored into a
+local variable (and not into a dictionary as in the sample above).

More information about the mono-bugs mailing list