[Mono-bugs] [Bug 58121][Nor] New - Exception in generic c# program

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 6 May 2004 06:42:23 -0400 (EDT)


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 mwh@sysrq.dk.

http://bugzilla.ximian.com/show_bug.cgi?id=58121

--- shadow/58121	2004-05-06 06:42:23.000000000 -0400
+++ shadow/58121.tmp.7904	2004-05-06 06:42:23.000000000 -0400
@@ -0,0 +1,75 @@
+Bug#: 58121
+Product: Mono: Compilers
+Version: unspecified
+OS: 
+OS Details: LFS
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: mwh@sysrq.dk               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Exception in generic c# program
+
+I use Mono Beta 1
+
+When I compile with gmcs and run the following program 
+I get an exception:
+
+using System;
+
+class Hello {
+
+        static void Main()
+        {
+                MyGenericClass<int> foo = new MyGenericClass<int>();
+                foo.Generic = 10;
+                Console.WriteLine (foo);
+
+                MyGenericClass<string> bar = 
+                                new MyGenericClass<string>();
+                bar.Generic = "Hello, World!";
+                Console.WriteLine (bar);
+
+                MyGenericClass<double> baz = 
+                                new MyGenericClass<double>();
+                baz.Generic = 10.5D;
+                Console.WriteLine (baz);
+        }
+}
+
+class MyGenericClass<T> {
+
+        T var;
+
+        public T Generic {
+                set { var = value; }
+        }
+
+        public override string ToString()
+        {
+                return var.GetType().ToString();
+        }
+
+}
+
+This is the output I get when running the program.
+
+System.Int32
+System.String
+ 
+Unhandled Exception: System.NullReferenceException: A null value was
+found where an object instance was required.
+in (unmanaged) MyGenericClass!1:ToString ()
+in <0x0001d> System.IO.TextWriter:Write (object)
+in <0x0000e> System.IO.TextWriter:WriteLine (object)
+in <0x00035> System.IO.SynchronizedWriter:WriteLine (object)
+in <0x0001a> System.Console:WriteLine (object)
+in <0x000d6> Hello:Main ()
+ 
+Segmentationerror