[Mono-bugs] [Bug 45149][Maj] New - Instance fields get initialized twice

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Thu, 19 Jun 2003 16:06:17 -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 sestoft@dina.kvl.dk.

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

--- shadow/45149	Thu Jun 19 16:06:17 2003
+++ shadow/45149.tmp.6386	Thu Jun 19 16:06:17 2003
@@ -0,0 +1,85 @@
+Bug#: 45149
+Product: Mono/MCS
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: sestoft@dina.kvl.dk               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Instance fields get initialized twice
+
+.Description of Problem:
+
+When an object instance constructor calls another one using the 
+
+    : this(...)
+
+mechanism, the class's instance fields get initialized twice.
+
+using System;
+
+class TestInit {
+  public static void Main(String[] args) {
+    new C();			// Should print: 1 2 3 4 5 6 7
+  }
+}
+
+class B { 
+  public readonly int fb1 = Print(3);
+
+  public B(int k) {
+    Print(5);
+  }
+
+  public readonly int fb2 = Print(4);
+
+  public static int Print(int i) {
+    Console.Write(i + " ");
+    return i;
+  }
+}
+
+class C : B {
+  public readonly int fc1 = Print(1);
+
+  public C() : this(0) {
+    Print(7);
+  }
+
+  public C(int k) : base(k) {
+    Print(6);
+  }
+
+  public readonly int fc2 = Print(2);
+}
+
+
+
+Steps to reproduce the problem:
+1. compile the above example using mcs-0.23
+2. run the .exe using either mono or MS CLR
+
+Actual Results:
+
+1 2 1 2 3 4 5 6 7
+
+Expected Results:
+
+1 2 3 4 5 6 7
+
+How often does this happen? 
+
+Always.
+
+Additional Information:
+
+The problem must be in mcs because the generated bytecode is wrong 
+under MS CLR as well as mono-0.23.