[Mono-bugs] [Bug 31051][Nor] New - Incorrect emitted code for multidimensional string array initializer

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
23 Sep 2002 19:21:40 -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 hwang_rob@yahoo.ca.

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

--- shadow/31051	Mon Sep 23 15:21:40 2002
+++ shadow/31051.tmp.7151	Mon Sep 23 15:21:40 2002
@@ -0,0 +1,83 @@
+Bug#: 31051
+Product: Mono/MCS
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: hwang_rob@yahoo.ca               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Incorrect emitted code for multidimensional string array initializer
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+
+Steps to reproduce the problem:
+
+using System;
+
+public class StringTest
+{
+    public static void Main()
+    {
+        string[,] t = new string[2,3] {{"a","b","c"}, {"1","2","3"}};
+
+        if (t[0,2] == "c") {
+            Console.WriteLine( "Pass" );
+        } else {
+            Console.WriteLine( "Fail" );
+        }
+
+    }
+}
+
+ 
+
+Actual Results:
+"Fail"
+
+Expected Results:
+"Pass"
+
+How often does this happen? 
+Always.
+
+Additional Information:
+It appears that incorrect code is emitted from method
+EmitDynamicInitializers of class ArrayCreation.  The following simple patch
+against expression.cs (1.355) seems to fix it for me, but since I am
+unfamiliar with this code, I don't claim that this is the best fix:
+
+--- expression.cs.orig  Mon Sep 23 10:09:08 2002
++++ expression.cs       Mon Sep 23 10:10:27 2002
+@@ -5058,8 +5058,7 @@
+ 
+                                                ig.Emit (OpCodes.Ldloc, temp);
+ 
+-                                               for (int idx = dims; idx >
+0; ) {
+-                                                       idx--;
++                                               for (int idx = 0; idx <
+dims; idx++) {
+                                                        IntConstant.EmitInt
+(ig, current_pos [idx]);
+                                                }
+ 
+@@ -5096,7 +5095,7 @@
+                                //
+                                // Advance counter
+                                //
+-                               for (int j = 0; j < dims; j++){
++                               for (int j = dims - 1; j >= 0; j--){
+                                        current_pos [j]++;
+                                        if (current_pos [j] < (int) bounds [j])
+                                                break;