Bugzilla – Bug 323320
[GMCS] Cannot compile foreach over generic collections
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by pawel.sakowski@mindbreeze.com 2007-01-26 05:35:48 MST ---- Description of Problem: In certain cases, gmcs isn't able to compile a foreach enumeration over a generic collection, emitting confusing messages regarding ambiguity of GetEnumerator(). The messages can be both warnings and errors. An example of both cases follows (I considered these related, so posting as a single bug report). Steps to reproduce the problem: 1. Download and unpack http://www.itu.dk/research/c5/Release1.0/C5.bin.zip 2. Create ambiguous-enumerable-warning.cs: using System.Collections.Generic; class X{static void Main(){ IDictionary<int,int> dict = new Dictionary<int,int>(); foreach (KeyValuePair<int,int> pair in dict) { System.Console.WriteLine(pair.Key); } }} 3. Create ambiguous-enumerable-error.cs: public class A: C5.ArrayList<int> {} class X{static void Main(){ A x = new A(); foreach (int i in x) { } }} 4. gmcs -warnaserror ambiguous-enumerable-warning.cs 5. gmcs /r:C5.dll ambiguous-enumerable-error.cs Actual Results: ambiguous-enumerable-warning.cs(4,1): error CS0278: `System.Collections.Generic.IDictionary<int,int>' contains ambiguous implementation of `enumerable' pattern. Method `System.Collections.IEnumerable.GetEnumerator()' is ambiguous with method `System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<int,int>>.GetEnumerator()' /usr/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error) /usr/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error) Compilation failed: 1 error(s), 0 warnings ambiguous-enumerable-error.cs(5,1): error CS1640: foreach statement cannot operate on variables of type `A' because it contains multiple implementation of `C5.ArrayBase<int>.GetEnumerator()'. Try casting to a specific implementation ambiguous-enumerable-error.cs(1,14): (Location of the symbol related to previous error) Compilation failed: 1 error(s), 0 warnings Expected Results: Two successes. How often does this happen? 100% Additional Information: Reproduces with mono 1.2.2.1 The test cases compile fine with both csc and mono 1.1.13.6. ---- Additional Comments From pawel.sakowski@mindbreeze.com 2007-01-26 09:27:44 MST ---- In case it's unclear: The expected results are not to produce any message (warning or error) on the foreach lines. ---- Additional Comments From rharinath@novell.com 2007-01-27 12:21:50 MST ---- I believe this has been fixed recently (though I haven't downloaded the testcase yet). Can you retry with a recent SVN snapshot and/or the 1.2.3 pretest? ---- Additional Comments From gert.driesen@pandora.be 2007-01-28 13:49:11 MST ---- The first issue (CS2078) is indeed resolved in SVN, however I can still reproduce the second issue (CS1640). ---- Additional Comments From martin@ximian.com 2007-04-03 15:14:15 MST ---- Fixed in SVN. ---- Additional Comments From martin@ximian.com 2007-04-03 15:14:42 MST ---- .