[Mono-bugs] [Bug 414165] New: Strange compiler error when using a lambda expression

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Aug 2 15:00:32 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=414165


           Summary: Strange compiler error when using a lambda expression
           Product: Mono: Compilers
           Version: 2.0
          Platform: x86-64
        OS/Version: Linux
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: mono at e-tobi.net
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


When trying to compile this code:

using System;



public class Cache<KEY, VALUE> where VALUE : class

{

    private readonly Func<KEY, VALUE> _onMissing = key =>
    {

        int x = 0;

        return null;    

    };


    public Cache()

    {

    }



    public Cache(Func<KEY, VALUE> onMissing)

    {

    }

}


I get the follwing error:

$ gmcs --version ;gmcs xxx.cs 
Mono C# compiler version 2.1.0.0
xxx.cs(7,13): warning CS0219: The variable `x' is assigned but its value is
never used
Exception caught by the compiler while emitting:
   Block that caused the problem begin at: xxx.cs(6,5):
System.Exception: Trying to emit a local from a different ILGenerator.
Internal compiler error at xxx.cs(5,56):: exception caught while emitting
MethodBuilder [Cache`2::<Cache>m__1]

Unhandled Exception: System.Exception: Trying to emit a local from a different
ILGenerator.
  at System.Reflection.Emit.ILGenerator.Emit (OpCode opcode,
System.Reflection.Emit.LocalBuilder local) [0x00000] 
  at Mono.CSharp.LocalInfo.EmitAssign (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.VariableReference.EmitAssign (Mono.CSharp.EmitContext ec,
Mono.CSharp.Expression source, Boolean leave_copy, Boolean prepare_for_load)
[0x00000] 
  at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean is_statement)
[0x00000] 
  at Mono.CSharp.Assign.EmitStatement (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.StatementExpression.DoEmit (Mono.CSharp.EmitContext ec)
[0x00000] 
  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.Block.Emit (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.EmitContext.EmitResolvedTopBlock (Mono.CSharp.ToplevelBlock
block, Boolean unreachable) [0x00000] 
  at Mono.CSharp.EmitContext.EmitTopBlock (IMethodData md,
Mono.CSharp.ToplevelBlock block) [0x00000] 

If I remove any of the ctors or the local variable "x" in the lambda, it
compiles, but not in the above combination.


-- 
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