[Mono-bugs] [Bug 67689][Wis] New - mcs compiles program w/ambiguous call between 2 GetEnumerator

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 6 Oct 2004 09:47:36 -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 rodolfocampero@hotmail.com.

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

--- shadow/67689	2004-10-06 09:47:36.000000000 -0400
+++ shadow/67689.tmp.8814	2004-10-06 09:47:36.000000000 -0400
@@ -0,0 +1,108 @@
+Bug#: 67689
+Product: Mono: Compilers
+Version: unspecified
+OS: GNU/Linux [Other]
+OS Details: Mandrake 10.0 CE with upgrades
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: rodolfocampero@hotmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: mcs compiles program w/ambiguous call between 2 GetEnumerator
+
+Description of Problem:
+mcs compiles the following program, which is rejected by Microsoft .NET 
+compiler:
+
+8<----------------------------------------------------------------
+using System;
+using System.Collections;
+
+namespace Testing {
+        interface ICustomEnumerable {
+                IEnumerator GetEnumerator();
+        }
+
+        interface IMixedEnumerable : IEnumerable, ICustomEnumerable {}
+
+        class TestCollection : IMixedEnumerable {
+                IEnumerator IEnumerable.GetEnumerator() {
+                        Console.WriteLine("IEnumerable");
+                        return null;
+                }
+
+                IEnumerator ICustomEnumerable.GetEnumerator()  {
+                        Console.WriteLine("ICustomEnumerable");
+                        return null;
+                }
+        }
+
+        class Test {
+                public static void Main(string[] args) {
+                        IMixedEnumerable c = new TestCollection();
+                        foreach(object o in c) {}
+                }
+        }
+}
+8<----------------------------------------------------------------
+
+Steps to reproduce the problem:
+1. Try to build the program. mcs <filename.cs> should be enough.
+
+Actual Results:
+The program is compiled.
+
+Expected Results:
+Compilation should fail; see csc output:
+
+The call is ambiguous between the following methods or
+properties: 'Testing.ICustomEnumerable.GetEnumerator()'
+and 'System.Collections.IEnumerable.GetEnumerator()'
+
+How often does this happen? 
+Always
+
+Additional Information:
+Even though someone confirmed that this is a bug
+(see http://lists.ximian.com/archives/public/mono-list/2004-
+October/023600.html)
+I'm not that sure, because the following program compiles fine in both 
+platforms (.NET and mono):
+
+8<---------------------------------------------------
+using System;
+using System.Collections;
+
+public interface IMyEnumerable {
+        IEnumerator GetEnumerator();
+}
+
+public class TestCol : IEnumerable, IMyEnumerable {
+        IEnumerator IEnumerable.GetEnumerator() {
+                Console.WriteLine("IEnumerable");
+                return null;
+        }
+
+        IEnumerator IMyEnumerable.GetEnumerator() {
+                Console.WriteLine("IMyEnumerable");
+                return null;
+        }
+
+        public static void Main(string[] args) {
+                TestCol t = new TestCol();
+                try {
+                        foreach(object o in t) {}
+                } catch(Exception) {}
+        }
+}
+8<---------------------------------------------------
+
+Note that in both sample programs, mcs always uses GetEnumerator from 
+System.Collections.IEnumerator within the foreach statement, as does csc 
+for the second one.