[Mono-bugs] [Bug 81121][Min] New - [GMCS] crash on unassigned new of generic type

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Mar 12 13:47:46 EDT 2007

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 andy.mortimer at ansys.com.


--- shadow/81121	2007-03-12 12:47:46.000000000 -0500
+++ shadow/81121.tmp.5775	2007-03-12 12:47:46.000000000 -0500
@@ -0,0 +1,79 @@
+Bug#: 81121
+Product: Mono: Compilers
+Version: 1.2
+OS Details: 
+Status: NEW   
+Priority: Minor
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: andy.mortimer at ansys.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+Summary: [GMCS] crash on unassigned new of generic type
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+Crash trying to compile code which creates a new object of the generic
+parameter for a class, but does not assign that new object to a variable.
+Steps to reproduce the problem:
+1. Create a file newcrash.cs containing the small class:
+public class SomeClass<T> where T : new() {
+    public void Foo() {
+        new T();
+    }
+2. gmcs /target:library newcrash.cs
+Actual Results:
+Compiler crashes with the following stack trace:
+Unhandled Exception: System.InvalidOperationException: Operation is not
+valid due to the current state of the object
+  at Mono.CSharp.New.EmitStatement (Mono.CSharp.EmitContext ec) [0x00000]
+  at Mono.CSharp.StatementExpression.DoEmit (Mono.CSharp.EmitContext ec)
+  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.EmitContext.EmitResolvedTopBlock
+(Mono.CSharp.ToplevelBlock block, Boolean unreachable) [0x00000]
+  at Mono.CSharp.EmitContext.EmitTopBlock (IMethodData md,
+Mono.CSharp.ToplevelBlock block) [0x00000]
+  at Mono.CSharp.MethodData.Emit (Mono.CSharp.DeclSpace parent) [0x00000]
+  at Mono.CSharp.Method.Emit () [0x00000]
+  at Mono.CSharp.TypeContainer.EmitType () [0x00000]
+  at Mono.CSharp.RootContext.EmitCode () [0x00000]
+  at Mono.CSharp.Driver.MainDriver (System.String[] args) [0x00000]
+  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000]
+(This trace is with; I'm told it also fails with the latest
+development version, but I don't know if the stack trace is the same.)
+Expected Results:
+Successful compilation.
+How often does this happen? 
+Every time.
+Additional Information:
+Assigning the result of the new() call to a variable prevents the crash:
+public class SomeClass<T> where T : new() {
+    public void Foo() {
+        T obj = new T();
+    }

More information about the mono-bugs mailing list