[Mono-bugs] [Bug 75571][Wis] New - bug in yield AND/OR foreach implementation

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sun Jul 17 20:54:08 EDT 2005


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 albertoavila at gmail.com.

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

--- shadow/75571	2005-07-17 20:54:08.000000000 -0400
+++ shadow/75571.tmp.3314	2005-07-17 20:54:08.000000000 -0400
@@ -0,0 +1,81 @@
+Bug#: 75571
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: JIT
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: albertoavila at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: bug in yield AND/OR foreach implementation
+
+Description of Problem:
+If you are writing a class that acts like a collection (implements
+IEumerable) and in the GetEnumerator you do something like:
+foreach (Type Item in this)
+   yield return Item;
+You get a Segmentation Fault
+
+
+Steps to reproduce the problem:
+1. Type this testcase: 
+using System;
+using System.Collections;
+
+public class Foo : IEnumerable {
+        int[] array = {1, 2, 3, 4, 5};
+
+        public int Count {
+                get {
+                        return array.Length;
+                }
+        }
+
+        public int this [int index] {
+                get {
+                        return array[index];
+                }
+        }
+
+        public IEnumerator GetEnumerator () {
+                foreach (int item in this)
+                        yield return item;
+        }
+
+        public static void Main (string[] args) {
+                Foo Bar = new Foo ();
+                foreach (int elem in Bar)
+                        Console.WriteLine (elem);
+        }
+}
+
+2. 
+Compile it
+3. 
+Run it
+Actual Results:
+Segmentation Fault
+
+Expected Results:
+Some kind of Exception
+
+
+How often does this happen? 
+Always
+
+Additional Information:
+
+I've not tested this on windows, but maybe it's the same.
+I know that the bug only happens when the developer do that lame mistake,
+but the mono runtime shouldn't cause a segmentation fault, some kind of
+exception would be nice.
+
+I didn't tested without the yield (the traditional way with a class that
+implements IEnumerator), but maybe it;s the same


More information about the mono-bugs mailing list