[Mono-bugs] [Bug 80249][Nor] New - [GMCS] incorrect compilation of foreach

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Dec 13 08:27:29 EST 2006


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 lupus at ximian.com.

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

--- shadow/80249	2006-12-13 08:27:29.000000000 -0500
+++ shadow/80249.tmp.9722	2006-12-13 08:27:29.000000000 -0500
@@ -0,0 +1,62 @@
+Bug#: 80249
+Product: Mono: Compilers
+Version: 1.2
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: lupus at ximian.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: [GMCS] incorrect compilation of foreach
+
+Given the following test:
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+class MyEnum : IEnumerator {
+	int count = 0;
+	public object Current {
+		get {return "";}
+	}
+	public bool MoveNext () {
+		if (count > 0)
+			return false;
+		count++;
+		return true;
+	}
+	public void Reset () {
+	}
+}
+class MyDict : IEnumerable<KeyValuePair<object,object>> {
+	IEnumerator<KeyValuePair<object, object>> IEnumerable<KeyValuePair<object,
+object>>.GetEnumerator() {
+		KeyValuePair<object, object> o = new KeyValuePair<object, object>
+("hello", "world");
+		yield return o;
+	}
+	public IEnumerator GetEnumerator() {
+		return new MyEnum ();
+	}
+}
+class T {
+	static void Main () {
+		MyDict dict = new MyDict ();
+		foreach (KeyValuePair<object, object> o in dict) {
+			Console.WriteLine ("{0} {1}", o.Key, o.Value);
+		}
+	}
+}
+
+Compiling with gmcs yields a cast exception. This is because gmcs
+calls the non-generic GetEnumerator() instead of the proper generic
+implementation that returns KeyValuePair<object, object values.
+This is a reduced test case from ironpython code. This bug makes a
+gmcs-compiled ironpython (1.1) unusable.


More information about the mono-bugs mailing list