Fix #80249
authorRaja R Harinath <harinath@hurrynot.org>
Thu, 11 Jan 2007 11:52:18 +0000 (11:52 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Thu, 11 Jan 2007 11:52:18 +0000 (11:52 -0000)
* mcs/statement.cs (CollectionForeach.TryType): Prefer generic
GetEnumerator over non-generic variant.  Fix code to follow comments.
* tests/gtest-302.cs: New test based on #80249.

svn path=/trunk/mcs/; revision=70850

mcs/mcs/ChangeLog
mcs/mcs/statement.cs
mcs/tests/ChangeLog
mcs/tests/gtest-302.cs [new file with mode: 0644]

index bff1d8a953716d4f543c1b9fa96d01ce70708367..ca96ffadff7cbee4ef2b935bc63dca37ec136857 100644 (file)
@@ -1,3 +1,9 @@
+2007-01-11  Raja R Harinath  <rharinath@novell.com>
+
+       Fix #80249
+       * statement.cs (CollectionForeach.TryType): Prefer generic
+       GetEnumerator over non-generic variant.  Fix code to follow comments.
+
 2007-01-09  Raja R Harinath  <rharinath@novell.com>
 
        Fix #80446
index e2d0752152fda1a988d891c25d17076a686d6865..56b0d24f1e6f15a52f9e56e6b0142f1fdf86eb12 100644 (file)
@@ -4917,7 +4917,7 @@ namespace Mono.CSharp {
                                                        if (!TypeManager.IsGenericType (mi.ReturnType))
                                                                continue;
 
-                                                       Report.SymbolRelatedToPreviousError(t);
+                                                       Report.SymbolRelatedToPreviousError (t);
                                                        Report.Error(1640, loc, "foreach statement cannot operate on variables of type `{0}' " +
                                                                "because it contains multiple implementation of `{1}'. Try casting to a specific implementation",
                                                                TypeManager.CSharpName (t), TypeManager.CSharpSignature (mi));
@@ -4925,13 +4925,13 @@ namespace Mono.CSharp {
                                                }
 
                                                // Always prefer generics enumerators
-                                               if (TypeManager.IsGenericType(mi.ReturnType))
-                                                       continue;
-
-                                               Report.SymbolRelatedToPreviousError (result);
-                                               Report.SymbolRelatedToPreviousError (mi);
-                                               Report.Warning (278, 2, loc, "`{0}' contains ambiguous implementation of `{1}' pattern. Method `{2}' is ambiguous with method `{3}'",
-                                                       TypeManager.CSharpName (t), "enumerable", TypeManager.CSharpSignature (result), TypeManager.CSharpSignature (mi));
+                                               if (!TypeManager.IsGenericType (mi.ReturnType)) {
+                                                       Report.SymbolRelatedToPreviousError (result);
+                                                       Report.SymbolRelatedToPreviousError (mi);
+                                                       Report.Warning (278, 2, loc, "`{0}' contains ambiguous implementation of `{1}' pattern. Method `{2}' is ambiguous with method `{3}'",
+                                                                       TypeManager.CSharpName (t), "enumerable", TypeManager.CSharpSignature (result), TypeManager.CSharpSignature (mi));
+                                                       return false;
+                                               }
                                        }
                                        result = mi;
                                        tmp_move_next = move_next;
index ef9643a432f01f879233799302f1a0e488fdfafe..8a0924cdc9bb7a460308fdd97381ecf8e3676adc 100644 (file)
@@ -1,3 +1,7 @@
+2007-01-11  Raja R Harinath  <rharinath@novell.com>
+
+       * gtest-302.cs: New test based on #80249.
+
 2007-01-09  Raja R Harinath  <rharinath@novell.com>
 
        * gtest-301.cs, gtest-301-lib.cs: New tests from #80446.
diff --git a/mcs/tests/gtest-302.cs b/mcs/tests/gtest-302.cs
new file mode 100644 (file)
index 0000000..ecf70bd
--- /dev/null
@@ -0,0 +1,20 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+interface ITest : IEnumerable<int> {
+}
+
+class Test : ITest {
+       IEnumerator IEnumerable.GetEnumerator () { throw new Exception (); }
+       IEnumerator<int> IEnumerable<int>.GetEnumerator () { yield break; }
+}
+
+class M {
+       static void Main ()
+       {
+               ITest foo = new Test ();
+               foreach (int i in foo)
+                       Console.WriteLine (i);
+       }
+}