[Mono-bugs] [Bug 24484] New - Variables declared in foreach are read-only

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
10 May 2002 05:55:45 -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 gonzalo@ximian.com.

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

--- shadow/24484	Fri May 10 01:55:45 2002
+++ shadow/24484.tmp.1497	Fri May 10 01:55:45 2002
@@ -0,0 +1,43 @@
+Bug#: 24484
+Product: Mono/MCS
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: gonzalo@ximian.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Variables declared in foreach are read-only
+
+Variables declared in foreach (int var in xxxx) are read-only variables
+inside the loop and mcs is not enforcing this.
+
+This is the test case:
+
+using System;
+
+public class MyTest {
+        public static void Main (string [] args)
+        {
+                int [] arr = new int [1000000];
+                int i, k;
+
+                for (k = 0; k < 100; k++){
+                        foreach (int b in arr){
+                                b = i++;
+                        }
+                }
+        }
+}
+
+Trying to compile it with csc says:
+foreach.cs(11,5): error CS1604: Cannot assign to 'b' because it is read-only
+
+And with mcs it compiles without any warning or error.