[Mono-bugs] [Bug 485378] New: Cannot resolve method overload

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Mar 14 00:14:55 EDT 2009


https://bugzilla.novell.com/show_bug.cgi?id=485378


           Summary: Cannot resolve method overload
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.4.x
          Platform: i386
        OS/Version: Mac OS X 10.4
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: Chuck.Esterbrook at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US;
rv:1.9.0.7) Gecko/2009021906 Firefox/3.0.7

/*
Mono C# bug: overload resolution

2009-03-13

This program is correct and compiles on .NET 3.5 and .NET 2.0.
It fails to compile on Mono 2.4 and 2.0 due to a false error.
I did not test Mono 2.2

The Mono C# compiler claims that an overload is ambiguous, but given that
MyCollection<T> inherits IMyCollection<T>, the compiler should favor the
overload that accepts that type.

This bug makes porting software from .NET to Mono difficult.
*/

using System;
using System.Collections.Generic;

interface IMyCollection<T> : ICollection<T> {

}

class MyCollection<T> : IMyCollection<T> {

    public void AddRange(IMyCollection<T> items) {
    }

    public void AddRange(IEnumerable<T> items) {
    }

    // ---

    public int Count { get { return 0; } }

    public bool IsReadOnly { get { return false; } }

    public void Add(T item) { }

    public void Clear() { }

    public bool Contains(T item) { return false; }

    public void CopyTo(T[] a, int i) { }

    public bool Remove(T item) { return false; }

    public IEnumerator<T> GetEnumerator() { return null; }

    System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator() { return null; }

}

class P {

    static protected MyCollection<String> foo = new MyCollection<String>();

    static protected MyCollection<String> bar = new MyCollection<String>();

    static public MyCollection<String> IgnoreTokens {
        get {
            if (foo.Count == 0)
                foo.AddRange(bar);  // false error on Mono 2.0 and 2.4: The
call is ambiguous between...
            return foo;
        }
    }

    public static void Main() {
        Console.WriteLine("done.");
    }

}


Reproducible: Always

Steps to Reproduce:
1. Compile the above program with gmcs


Actual Results:  
False compilation error:

error CS0121: The call is ambiguous between the following methods or
properties:
`MyCollection<string>.AddRange(System.Collections.Generic.IEnumerable<string>)'
and `MyCollection<string>.AddRange(IMyCollection<string>)'

Expected Results:  
No compilation errors like on .NET.


This may be related to https://bugzilla.novell.com/show_bug.cgi?id=444388

I cannot tell if these are the actual same bug or just in the same area. At the
very least, the program submitted with this bug report makes a nice additional
test case involving generics and method arguments.

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list