[Mono-list] foreach and GetEnumerator (with fixed test case)
Rodolfo Campero
rodolfocampero@hotmail.com
Tue, 05 Oct 2004 23:10:40 +0000
Hello,
I'm resending this email, this time with a sample that actually
reproduces the problem - I checked it in both MS .NET and mono 1.1.1.0.
Sorry for the previous one.
Considering that the previous sample actually compiles and run in MS
.NET, now I'm thinking it's a bug in csc... anyway, I'd like to read
your comments, and if a mono hacker considers it's a mono bug, I can
file a bug report.
Here goes the testcase; it doesn't compile on Windows, but it does on
mono (if you run it, you'll get a NullReferenceException but that's ok):
compiled with:
Microsoft (R) Visual C# .NET Compiler version 7.00.9951
for Microsoft (R) .NET Framework version 1.0.3705
The error is in the line that contains the 'foreach' statement:
The call is ambiguous between the following methods or
properties: 'Testing.ICustomEnumerable.GetEnumerator()'
and 'System.Collections.IEnumerable.GetEnumerator()'
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<----------------------------------------------------------------
El lun, 04-10-2004 a las 20:04, Rodolfo Campero escribió:
>Hello,
>
>I've run into a situation with foreachs and the GetEnumerator method.
>The issue is reproduced with this small piece of code:
>
<the wrong example was removed/>
>This program can be compiled using mcs, and when I run it I get:
>
> $ mono cols.exe
> IEnumerable
>
>The problem is that this same piece of code won't compile in MS.NET csc
>compiler (I checked my original program with version 1.1, but not this
>simplified example): it complains that it can't choose between
>System.Collections.IEnumerable and IMyEnumerable.
>
>I'm rising this question because I'm not sure if this is a mono or a MS
>.NET bug, because I find the spec (ECMA-334, 15.8.4) rather ambiguous.
>At a given point it reads:
>
> "A type C is said to be a collection type if it implements
> "the System.IEnumerable interface or implements the collection
> "pattern by meeting all of the following criteria: [...]"
>
>The thing is that it's not specified what happens when _both_ criteria
>are met.
>
>So, what do you think?
>
>Looking forward to reading all your comments,
>
>Rodolfo
_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?page=features/virus