[Mono-bugs] [Bug 569827] New: Multiple overloads of an extension method can be incorrectly marked as ambiguous
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Mon Jan 11 18:10:53 EST 2010
http://bugzilla.novell.com/show_bug.cgi?id=569827
http://bugzilla.novell.com/show_bug.cgi?id=569827#c0
Summary: Multiple overloads of an extension method can be
incorrectly marked as ambiguous
Classification: Mono
Product: Mono: Compilers
Version: SVN
Platform: Macintosh
OS/Version: Mac OS X 10.6
Status: NEW
Severity: Normal
Priority: P5 - None
Component: C#
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: dmitchell at logos.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Blocker: ---
Created an attachment (id=336004)
--> (http://bugzilla.novell.com/attachment.cgi?id=336004)
A copy of the code listing from the description.
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us)
AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10
Consider the following C# program:
===
using System;
namespace MonoBugs
{
public struct Foo<T>
{
public T Item;
}
public static class Bar
{
public static void DoStuff<T>(this T item, Action<T> fn)
where T : class
{
Console.WriteLine("First overload");
if (item != null)
fn(item);
}
public static void DoStuff<T>(this T? item, Action<T> fn)
where T : struct
{
Console.WriteLine("Second overload");
if (item.HasValue)
fn(item.Value);
}
}
public static class Program
{
public static void Main()
{
Foo<int>? value = new Foo<int> { Item = 3 };
value.DoStuff(x => Console.WriteLine(x.Item));
}
}
}
===
Under Microsoft's .NET implementation, this code compiles and runs just fine,
correctly selecting the second overload of DoStuff when it is invoked on the
second line of Main().
Mono, on the other hand, incorrectly fails to compile with an error message
similar to
foo.cs(39,31): error CS0121: The call is ambiguous between the following
methods or properties: `MonoBugs.Bar.DoStuff<MonoBugs.Foo<int>>(this
MonoBugs.Foo<int>?, System.Action<MonoBugs.Foo<int>>)' and
`MonoBugs.Bar.DoStuff<MonoBugs.Foo<int>?>(this MonoBugs.Foo<int>?,
System.Action<MonoBugs.Foo<int>?>)'
This probably happens either because Nullable<Foo<int>>? is being treated as a
class for the purpose of generic constraint checking or because generic
constraints are not being fully checked before the compiler gives up.
Reproducible: Always
Steps to Reproduce:
1. Take the program listing from the details and put it in a file
2. Compile the file with gmcs
3.
Actual Results:
The compiler fails with a message similar to
foo.cs(39,31): error CS0121: The call is ambiguous between the following
methods or properties: `MonoBugs.Bar.DoStuff<MonoBugs.Foo<int>>(this
MonoBugs.Foo<int>?, System.Action<MonoBugs.Foo<int>>)' and
`MonoBugs.Bar.DoStuff<MonoBugs.Foo<int>?>(this MonoBugs.Foo<int>?,
System.Action<MonoBugs.Foo<int>?>)'
Expected Results:
The compiler should emit a program that correctly calls the second overload of
DoStuff.
--
Configure bugmail: http://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