[Mono-bugs] [Bug 24558] New - mcs/mono don't recognize instantiating an abstract class

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
11 May 2002 13:06:14 -0000


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 detlev@die-offenbachs.de.

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

--- shadow/24558	Sat May 11 09:06:14 2002
+++ shadow/24558.tmp.11050	Sat May 11 09:06:14 2002
@@ -0,0 +1,93 @@
+Bug#: 24558
+Product: Mono/MCS
+Version: unspecified
+OS: 
+OS Details: SuSE 8.0
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: detlev@die-offenbachs.de               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: mcs/mono don't recognize instantiating an abstract class
+
+mcs/mono v0.11 do not recognize the attempt to create an instance of an
+abstract class. The errormessage I got was
+
+** WARNING **: unhandled exception System.NullReferenceException: "A null
+value was found where an object instance was required"
+TODO: implement stack traces
+
+However, more helpful would be something like
+
+Cannot create an instance of the abstract class or interface 'Window'.
+
+The faulty code is as follows.
+
+---------------------------------------------------
+using System;
+
+abstract public class Window {
+    // constructor takes two integers to
+    // fix location on the console
+    public Window(int top, int left) {
+        this.top = top;
+        this.left = left;
+    }
+
+    // simulates drawing the window
+    // notice: no implementation
+    abstract public void DrawWindow();
+
+    protected int top;
+    protected int left;
+}
+
+// ListBox derives from Window
+public class ListBox : Window {
+    // constructor adds a parameter
+    public ListBox(int top, int left, string contents) :
+        base(top, left) {       // call base constructor
+        listBoxContents = contents;
+    }
+    
+    // an overridden version implementing the
+    // abstract method
+    public override void DrawWindow() {
+        Console.WriteLine("Writing string to the listbox: {0}",
+            listBoxContents);
+    }
+
+    private string listBoxContents;    // new member variable
+}
+
+public class Button : Window {
+    public Button(int top, int left) : base(top, left) {
+    }
+
+    // implement the abstract method
+    public override void DrawWindow() {
+        Console.WriteLine("Drawing Button at {0}, {1}\n",
+            top, left);
+    }
+}
+
+public class Tester {
+    public static void Main() {
+        Window[] winArray = new Window[3];
+// next line is in error
+        winArray[0] = new Window(1, 2);
+        winArray[1] = new ListBox(3, 4, "Listbox in array");
+        winArray[2] = new Button(5, 6);
+
+        for (int i=0; i<3; i++) {
+            winArray[i].DrawWindow();
+        }
+    }
+}
+-----------------------------------------------------