[Mono-bugs] [Bug 610919] New: Cannot use anonymous delegates inside explicit events

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Jun 2 06:38:21 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=610919

http://bugzilla.novell.com/show_bug.cgi?id=610919#c0


           Summary: Cannot use anonymous delegates inside explicit events
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.6.x
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: amcgovern at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Created an attachment (id=366380)
 --> (http://bugzilla.novell.com/attachment.cgi?id=366380)
testcase

In the attached testcase, gmcs hates wrapping the 'value' in the 'add' handler
in an anonymous delegate. If you changed the add handler to read:

add {
    var v = value;
    myEvent += delegate { v (this, EventArgs.Empty); };
}

then it compiles perfectly and gives the expected output of:
Hey! from BaseTest.MainClass / System.EventArgs


Right now it gives the output:

Internal compiler error at a.cs(11,45):: exception caught while emitting
MethodBuilder [<>c__AnonStorey1::<>m__1]

Unhandled Exception: System.ArgumentException: Trying to emit a local from a
different ILGenerator.
  at System.Reflection.Emit.ILGenerator.Emit (OpCode opcode,
System.Reflection.Emit.LocalBuilder local) [0x0038b] in
/data/Projects/mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs:721 
  at Mono.CSharp.EmitContext.Emit (OpCode opcode,
System.Reflection.Emit.LocalBuilder local) [0x00000] in
/data/Projects/mcs/mcs/codegen.cs:417 
  at Mono.CSharp.LocalTemporary.Emit (Mono.CSharp.EmitContext ec) [0x00016] in
/data/Projects/mcs/mcs/assign.cs:222 
  at Mono.CSharp.MemberExpr.EmitInstance (Mono.CSharp.EmitContext ec, Boolean
prepare_for_load) [0x0006d] in /data/Projects/mcs/mcs/ecore.cs:2829 
  at Mono.CSharp.FieldExpr.Emit (Mono.CSharp.EmitContext ec, Boolean
leave_copy) [0x00067] in /data/Projects/mcs/mcs/ecore.cs:4532 
  at Mono.CSharp.HoistedVariable.Emit (Mono.CSharp.EmitContext ec, Boolean
leave_copy) [0x00000] in /data/Projects/mcs/mcs/anonymous.cs:656 
  at Mono.CSharp.VariableReference.Emit (Mono.CSharp.EmitContext ec, Boolean
leave_copy) [0x0000e] in /data/Projects/mcs/mcs/expression.cs:4350 
  at Mono.CSharp.VariableReference.Emit (Mono.CSharp.EmitContext ec) [0x00000]
in /data/Projects/mcs/mcs/expression.cs:4325 
  at Mono.CSharp.Invocation.EmitCall (Mono.CSharp.EmitContext ec, Boolean
is_base, Mono.CSharp.Expression instance_expr, Mono.CSharp.MethodSpec method,
Mono.CSharp.Arguments Arguments, Location loc, Boolean dup_args, Boolean
omit_args) [0x00163] in /data/Projects/mcs/mcs/expression.cs:5138 
  at Mono.CSharp.Invocation.EmitCall (Mono.CSharp.EmitContext ec, Boolean
is_base, Mono.CSharp.Expression instance_expr, Mono.CSharp.MethodSpec method,
Mono.CSharp.Arguments Arguments, Location loc) [0x00000] in
/data/Projects/mcs/mcs/expression.cs:5065 
  at Mono.CSharp.DelegateInvocation.Emit (Mono.CSharp.EmitContext ec) [0x00000]
in /data/Projects/mcs/mcs/delegate.cs:720 
  at Mono.CSharp.DelegateInvocation.EmitStatement (Mono.CSharp.EmitContext ec)
[0x00000] in /data/Projects/mcs/mcs/delegate.cs:725 
  at Mono.CSharp.StatementExpression.DoEmit (Mono.CSharp.EmitContext ec)
[0x00000] in /data/Projects/mcs/mcs/statement.cs:619 
  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x0000c] in
/data/Projects/mcs/mcs/statement.cs:67 
  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00014] in
/data/Projects/mcs/mcs/statement.cs:2141 
  at Mono.CSharp.Block.Emit (Mono.CSharp.EmitContext ec) [0x0001e] in
/data/Projects/mcs/mcs/statement.cs:2151 
  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x0004d] in
/data/Projects/mcs/mcs/statement.cs:2297 
  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00030] in
/data/Projects/mcs/mcs/statement.cs:2831 
  at Mono.CSharp.MethodData.Emit (Mono.CSharp.DeclSpace parent) [0x000d1] in
/data/Projects/mcs/mcs/method.cs:1911 
  at Mono.CSharp.MethodOrOperator.Emit () [0x001a9] in
/data/Projects/mcs/mcs/method.cs:608 
  at Mono.CSharp.Method.Emit () [0x00112] in
/data/Projects/mcs/mcs/method.cs:1134

-- 
Configure bugmail: http://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