[Mono-bugs] [Bug 659771] New: gmcs: anon method that captures local var in finalizer crashes compiler
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Wed Dec 15 16:35:54 EST 2010
https://bugzilla.novell.com/show_bug.cgi?id=659771
https://bugzilla.novell.com/show_bug.cgi?id=659771#c0
Summary: gmcs: anon method that captures local var in finalizer
crashes compiler
Classification: Mono
Product: Mono: Compilers
Version: 2.8.x
Platform: Macintosh
OS/Version: Mac OS X 10.6
Status: NEW
Severity: Normal
Priority: P5 - None
Component: C#
AssignedTo: msafar at novell.com
ReportedBy: brian at sooloos.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Blocker: ---
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US)
AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.19 Safari/534.13
If I try to compile an anonymous method inside of a finalizer and it captures a
variable in the local scope of the finalizer, gmcs crashes.
Yes, I am aware of how weird it is to do this and how obscure a case it really
is :)
brian at brianmbp ~ $ cat t.cs
using System;
using System.Threading;
class Foo {
~Foo() {
int x = 1;
new Thread(() => Console.WriteLine("{0}", x));
}
public static void Main(string[] args) { }
}
brian at brianmbp ~ $ gmcs t.cs
Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object
at Mono.CSharp.HoistedVariable.GetFieldExpression (Mono.CSharp.EmitContext
ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.HoistedVariable.EmitAssign (Mono.CSharp.EmitContext ec,
Mono.CSharp.Expression source, Boolean leave_copy, Boolean prepare_for_load)
[0x00000] in <filename unknown>:0
at Mono.CSharp.VariableReference.EmitAssign (Mono.CSharp.EmitContext ec,
Mono.CSharp.Expression source, Boolean leave_copy, Boolean prepare_for_load)
[0x00000] in <filename unknown>:0
at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean is_statement)
[0x00000] in <filename unknown>:0
at Mono.CSharp.Assign.EmitStatement (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0
at Mono.CSharp.StatementExpression.DoEmit (Mono.CSharp.EmitContext ec)
[0x00000] in <filename unknown>:0
at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0
at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0
at Mono.CSharp.Block.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename
unknown>:0
at Mono.CSharp.TryFinally.EmitTryBody (Mono.CSharp.EmitContext ec) [0x00000]
in <filename unknown>:0
at Mono.CSharp.ExceptionStatement.DoEmit (Mono.CSharp.EmitContext ec)
[0x00000] in <filename unknown>:0
at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0
at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0
at Mono.CSharp.Block.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename
unknown>:0
at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0
at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0
at Mono.CSharp.MethodData.Emit (Mono.CSharp.DeclSpace parent) [0x00000] in
<filename unknown>:0
at Mono.CSharp.MethodOrOperator.Emit () [0x00000] in <filename unknown>:0
at Mono.CSharp.Destructor.Emit () [0x00000] in <filename unknown>:0
at Mono.CSharp.TypeContainer.EmitType () [0x00000] in <filename unknown>:0
at Mono.CSharp.RootContext.EmitCode () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename
unknown>:0
at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename
unknown>:0
Reproducible: Always
This is easily worked around by moving the the code containing the anon method
to a separate method or static method on the class.
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list