[Mono-bugs] [Bug 32192][Wis] New - strange behaviour with ref types

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
12 Oct 2002 08:15:39 -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=32192

--- shadow/32192	Sat Oct 12 04:15:39 2002
+++ shadow/32192.tmp.11423	Sat Oct 12 04:15:39 2002
@@ -0,0 +1,99 @@
+Bug#: 32192
+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: strange behaviour with ref types
+
+(This is one of probably a few bugs related to variations of this
+particular code i'm going to file; they may be related bugs.)
+
+Given:
+
+/*t12.cs*/
+using System;
+
+public class Foo {
+        public static int counter = 0;
+        int my_counter;
+        Foo last_foo;
+
+        public Foo () {
+                my_counter = counter++;
+                Console.WriteLine (" Foo: my_counter = " + my_counter);
+        }
+
+        public Foo (ref Foo last)
+                : this ()
+        {
+                last_foo = last;
+                Console.WriteLine ("  with last " + 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[3];
+
+                foos[0] = new Foo ();
+                foos[1] = new Foo (ref foos[0]);
+                foos[2] = new Foo (ref foos[1]);
+
+                Console.WriteLine (foos[2].Frob ());
+        }
+}
+/**end**/
+
+The expected output, from microsoft's runtime:
+
+ Foo: my_counter = 0
+ Foo: my_counter = 1
+  with last 0
+ Foo: my_counter = 2
+  with last 1
+#2 #1 #0 !
+~Foo: my_counter = 2
+~Foo: my_counter = 1
+~Foo: my_counter = 0
+
+With mono (cvs HEAD, built with gc6.1, behaviour is same with GC_DONT_GC=1):
+
+ Foo: my_counter = 0
+ Foo: my_counter = 1
+  with last 0
+ Foo: my_counter = 2
+  with last 7
+#2 #7 #0 !
+~Foo: my_counter = 1
+~Foo: my_counter = 2
+~Foo: my_counter = 0
+
+The destructor order is different, but this may be irrelevant, but the "7"
+is odd...