[Mono-list] foreach and GetEnumerator (with fixed test case)

RoBiK robik@mailbox.sk
Wed, 6 Oct 2004 13:23:29 +0200


Hi,

I think this is a mono c# compiler error. Because there are two
GetEnumerator() methods with the same signature, the compiler should =
report
an error on the foreach statement. The microsoft compiler does it right =
wit
the "The call is ambiguous between the following methods or properties"
error message.

Robert

-----Original Message-----
From: mono-list-admin@lists.ximian.com
[mailto:mono-list-admin@lists.ximian.com] On Behalf Of Rodolfo Campero
Sent: Mittwoch, 06. Oktober 2004 01:11
To: mono-list@lists.ximian.com
Subject: [Mono-list] foreach and GetEnumerator (with fixed test case)

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 =3D new TestCollection();
                        foreach(object o in c) {}
                }
        }
}
8<----------------------------------------------------------------

El lun, 04-10-2004 a las 20:04, Rodolfo Campero escribi=F3:
>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=20
>simplified example): it complains that it can't choose between=20
>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=20
>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=3Dfeatures/virus

_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list