[Mono-bugs] [Bug 62740][Wis] New - mcs fails to reject inaccessible GetEnumerator() in foreach

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Mon, 9 Aug 2004 16:47:28 -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 atsushi@ximian.com.

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

--- shadow/62740	2004-08-09 16:47:28.000000000 -0400
+++ shadow/62740.tmp.8679	2004-08-09 16:47:28.000000000 -0400
@@ -0,0 +1,55 @@
+Bug#: 62740
+Product: Mono: Compilers
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: atsushi@ximian.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: mcs fails to reject inaccessible GetEnumerator() in foreach
+
+For inaccessible GetEnumerator() of a collection object that is iterated in
+foreach, it must be rejected. Currently mcs fails to reject it.
+
+-------
+using System;
+using System.Collections;
+
+public class Test
+{
+        public static void Main ()
+        {
+                Foo f = new Foo ();
+                foreach (object o in f)
+                        Console.WriteLine (o);
+        }
+}
+
+public class Foo
+{
+        internal IEnumerator GetEnumerator ()
+        {
+                return new ArrayList ().GetEnumerator ();
+        }
+}
+
+
+Actual Results:
+Compilation succeeded.
+
+Expected Results:
+$ csc foreach.cs -nologo
+foreach.cs(9,3): error CS1579: foreach statement cannot operate on variables of
+        type 'Foo' because 'Foo' does not contain a definition for
+        'GetEnumerator', or it is inaccessible
+
+How often does this happen? 
+Always.