[Mono-bugs] [Bug 403033] New: "return" in methods with anon methods -> invalid IL

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Jun 23 19:54:39 EDT 2008


           Summary: "return" in methods with anon methods -> invalid IL
           Product: Mono: Compilers
           Version: 1.9.0
          Platform: x86-64
        OS/Version: Linux
            Status: NEW
          Severity: Critical
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: Dax at daxxfiles.net
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

Using "return" in methods using anonymous methods accessing variables in the
methods scope (instead of in it's (anon meth) scope) confuses mcs really badly.

Whenever one places a "return" in a method hosting anonymous methods which in
turn access variables inside the hosting method, mcs places IL ret only at the
places it finds a "return". That particular instruction is surrounded by the
construction of multiple compiler generated classes and assignments. After
those assignments, the method body stops abruptly, even without a closing IL
In conclusion, using "return" and anonymous method accessing variables of less
limited scope sends mcs completely out of the window.

How to reproduce:
compile and run: 
using System; 
class Program { 
  static void Main() { 
    double pi = 1.0;
    Converter<int, double> c = delegate(int a) { return a * pi; };

Actual result:
Runtime throws InvalidProgramException.
C# disassembly:
private static void Main()
   <>c__CompilerGenerated0 generated = new <>c__CompilerGenerated0();
   <>c__CompilerGenerated2 generated2 = new <>c__CompilerGenerated2();
   generated2.<3:scope1> = generated;

Expected result:
No exception, no output.
C# disassembly:
private static void Main()

Additional info:
Seems to be fixed in SVN.

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list