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: [email protected] ReportedBy: [email protected] QAContact: [email protected] 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. _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
