[Mono-bugs] [Bug 54902][Wis] New - Iterators cannot be used inside operators or (getter) property accessors

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 26 Feb 2004 12:29:06 -0500 (EST)


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 sourcejedi@phonecoop.coop.

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

--- shadow/54902	2004-02-26 12:29:06.000000000 -0500
+++ shadow/54902.tmp.24392	2004-02-26 12:29:06.000000000 -0500
@@ -0,0 +1,70 @@
+Bug#: 54902
+Product: Mono/Compilers
+Version: unspecified
+OS: other
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: sourcejedi@phonecoop.coop               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Iterators cannot be used inside operators or (getter) property accessors
+
+Description of Problem: 
+ 
+If you use iterators - ie the yield keyword - inside an operator or a 
+"get" property accessor - the compiler fails with an error that suggests 
+it should not fail. 
+ 
+The following example shows an attempt to use a yield statement within an 
+operator 
+ 
+Steps to reproduce the problem: 
+1.  
+#enter source for Test.cs 
+cat > Test.cs << EOF 
+ 
+using System.Collections; 
+ 
+public abstract class Enumerable : IEnumerable { 
+        public abstract IEnumerator GetEnumerator (); 
+ 
+        public static Enumerable operator + (Enumerable a, Enumerable b) 
+        { 
+                IEnumerator ienum = a.GetEnumerator (); 
+                while (ienum.MoveNext ()) 
+                        yield return ienum.Current; 
+ 
+                ienum = b.GetEnumerator (); 
+                while (ienum.MoveNext ()) 
+                        yield return ienum.Current; 
+        } 
+} 
+ 
+ 
+2.  
+#compile test.cs 
+mcs Test.cs 
+  
+ 
+Actual Results: 
+ 
+Test.cs(10) error CS0204: yield statement can only be used within a 
+method, operator or property 
+Test.cs(14) error CS0204: yield statement can only be used within a 
+method, operator or property 
+Compilation failed: 2 error(s), 0 warnings 
+ 
+Expected Results: 
+ 
+Compilation succeeded 
+ 
+How often does this happen?  
+ 
+Always