[Mono-bugs] [Bug 32193][Wis] New - bug with arrays, object constructors, and ref types
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
12 Oct 2002 08:55:03 -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 vladimir@pobox.com.
http://bugzilla.ximian.com/show_bug.cgi?id=32193
--- shadow/32193 Sat Oct 12 04:55:03 2002
+++ shadow/32193.tmp.20507 Sat Oct 12 04:55:03 2002
@@ -0,0 +1,121 @@
+Bug#: 32193
+Product: Mono/Runtime
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: vladimir@pobox.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: bug with arrays, object constructors, and ref types
+
+Given:
+/*t13.cs*/
+using System;
+
+public class Foo {
+ public static int counter = 0;
+ public int my_counter;
+ public Foo last_foo;
+
+ public Foo () {
+ my_counter = counter++;
+ Console.WriteLine (" Foo: my_counter = " + my_counter);
+ }
+
+ public Foo (ref Foo last)
+ : this ()
+ {
+ last_foo = last;
+ if (last_foo == null) {
+ Console.WriteLine (" with null last_foo!");
+ } else {
+ Console.WriteLine (" with reference to " +
+last_foo.my_counter);
+ }
+ }
+
+ ~Foo () {
+ Console.WriteLine ("~Foo: my_counter = " + my_counter);
+ }
+
+ public string LastFrob () {
+ if (last_foo != null) {
+ return last_foo.Frob ();
+ } else {
+ return "!";
+ }
+ }
+
+ public string Frob () {
+ return "#" + my_counter + " " + LastFrob ();
+ }
+}
+
+public class Driver {
+ public static void Main () {
+ Foo[] foos = new Foo[5];
+
+ Console.WriteLine ("About to create foos");
+
+ for (int i = 0; i < foos.Length; i++) {
+ if (i != 0)
+ foos[i] = new Foo (ref foos[i-1]);
+ else
+ foos[i] = new Foo ();
+ }
+
+ Console.WriteLine (foos[4].Frob ());
+ }
+}
+/*end*/
+
+(Note: may be related to 32192. Foo class is pretty much the same, except
+with an extra print.)
+
+Expected output (microsoft runtime):
+
+About to create foos
+ Foo: my_counter = 0
+ Foo: my_counter = 1
+ with reference to 0
+ Foo: my_counter = 2
+ with reference to 1
+ Foo: my_counter = 3
+ with reference to 2
+ Foo: my_counter = 4
+ with reference to 3
+#4 #3 #2 #1 #0 !
+~Foo: my_counter = 4
+~Foo: my_counter = 3
+~Foo: my_counter = 2
+~Foo: my_counter = 1
+~Foo: my_counter = 0
+
+mono output:
+About to create foos
+ Foo: my_counter = 0
+ Foo: my_counter = 1
+ with reference to 0
+ Foo: my_counter = 2
+ with null last_foo!
+ Foo: my_counter = 3
+
+Unhandled Exception: System.NullReferenceException: A null value was found
+where an object
+instance was required
+in <0x0007e> 00 .Foo:.ctor (Foo&)
+in <0x000a4> 00 .Driver:Main ()
+
+mint executes correctly.
+
+I can't quite see what's going on here.. executes correctly without the
+ref's. Same results with both mcs and csc-compiled assemblies. (Please
+change the summary to something more indicative of what this bug is)