Better error message when type inference resolves valid types but parameter types...
authorMarek Safar <marek.safar@gmail.com>
Mon, 28 Oct 2013 12:08:58 +0000 (13:08 +0100)
committerMarek Safar <marek.safar@gmail.com>
Mon, 28 Oct 2013 12:08:58 +0000 (13:08 +0100)
mcs/errors/cs0162-19.cs [new file with mode: 0644]
mcs/errors/cs0411-15.cs [deleted file]
mcs/errors/cs0411-7.cs [deleted file]
mcs/errors/cs1503-14.cs [new file with mode: 0644]
mcs/errors/cs1503-15.cs [new file with mode: 0644]
mcs/errors/cs1503-16.cs [new file with mode: 0644]
mcs/mcs/ecore.cs
mcs/mcs/expression.cs

diff --git a/mcs/errors/cs0162-19.cs b/mcs/errors/cs0162-19.cs
new file mode 100644 (file)
index 0000000..b1f6ea3
--- /dev/null
@@ -0,0 +1,14 @@
+// CS0162: Unreachable code detected
+// Line: 12
+// Compiler options: -warnaserror
+
+public class X
+{
+       static void test (int stop)
+       {
+               int pos = 0;
+               do {
+                       break;
+               } while (pos < stop);
+       }
+}
diff --git a/mcs/errors/cs0411-15.cs b/mcs/errors/cs0411-15.cs
deleted file mode 100644 (file)
index ed39e45..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// CS0411: The type arguments for method `C.Foo<T>(IFoo<T>, IFoo<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly
-// Line: 17
-
-interface IFoo<in T>
-{
-}
-
-class C
-{
-       public static void Foo<T> (IFoo<T> e1, IFoo<T> e2)
-       {
-       }
-       
-       public static void Main ()
-       {
-               IFoo<int> a = null;
-               IFoo<object> b = null;
-               Foo (a, b);
-       }
-}
diff --git a/mcs/errors/cs0411-7.cs b/mcs/errors/cs0411-7.cs
deleted file mode 100644 (file)
index c22648e..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// CS0411: The type arguments for method `C.Foo<T>(T, System.Collections.Generic.Comparer<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly
-// Line: 20
-
-using System;
-using System.Collections.Generic;
-
-public class C
-{
-       static void Foo<T>(T t, Comparer<T> tc)
-       {
-       }
-       
-       static int Compare (int a, int b)
-       {
-               return -1;
-       }
-       
-       public static void Main ()
-       {
-               Foo (1, Compare);
-       }
-}
diff --git a/mcs/errors/cs1503-14.cs b/mcs/errors/cs1503-14.cs
new file mode 100644 (file)
index 0000000..26422fa
--- /dev/null
@@ -0,0 +1,25 @@
+// CS1503: Argument `#2' cannot convert `IContravariant<object>' expression to type `ICovariant<string>'
+// Line: 23
+
+interface IContravariant<in T>
+{
+}
+
+interface ICovariant<out T>
+{
+}
+
+class C
+{
+       public static void Test<T> (ICovariant<T> e1, ICovariant<T> e2)
+       {
+       }
+
+       public static void Main ()
+       {
+               ICovariant<string> a_2 = null;
+               IContravariant<object> b_2 = null;
+
+               Test (a_2, b_2);
+       }
+}
\ No newline at end of file
diff --git a/mcs/errors/cs1503-15.cs b/mcs/errors/cs1503-15.cs
new file mode 100644 (file)
index 0000000..4313fcf
--- /dev/null
@@ -0,0 +1,20 @@
+// CS1503: Argument `#2' cannot convert `IFoo<object>' expression to type `IFoo<int>'
+// Line: 18
+
+interface IFoo<in T>
+{
+}
+
+class C
+{
+       public static void Foo<T> (IFoo<T> e1, IFoo<T> e2)
+       {
+       }
+       
+       public static void Main ()
+       {
+               IFoo<int> a = null;
+               IFoo<object> b = null;
+               Foo (a, b);
+       }
+}
diff --git a/mcs/errors/cs1503-16.cs b/mcs/errors/cs1503-16.cs
new file mode 100644 (file)
index 0000000..24fa1e6
--- /dev/null
@@ -0,0 +1,22 @@
+// CS1503: Argument `#2' cannot convert `method group' expression to type `System.Collections.Generic.Comparer<int>'
+// Line: 20
+
+using System;
+using System.Collections.Generic;
+
+public class C
+{
+       static void Foo<T>(T t, Comparer<T> tc)
+       {
+       }
+       
+       static int Compare (int a, int b)
+       {
+               return -1;
+       }
+       
+       public static void Main ()
+       {
+               Foo (1, Compare);
+       }
+}
index 31c8a8b47edced1240ee43100ce5e32a866a30de..0e2cb2a6bcaf424321ed472c98a6eaee9de34433 100644 (file)
@@ -5266,7 +5266,7 @@ namespace Mono.CSharp {
                                                if (ms.TypeArguments != null)
                                                        constr_ok = new ConstraintChecker (rc.MemberContext).CheckAll (ms.GetGenericMethodDefinition (), ms.TypeArguments, ms.Constraints, loc);
 
-                                               if (ta_count == 0) {
+                                               if (ta_count == 0 && ms.TypeArguments == null) {
                                                        if (custom_errors != null && custom_errors.TypeInferenceFailed (rc, best_candidate))
                                                                return;
 
index 7a9155ba50b4e271b15c7c2d3aa95a7fd0ba0086..5729d7581baa508915f3bd10a8835fca1d589bf2 100644 (file)
@@ -6014,7 +6014,17 @@ namespace Mono.CSharp
 
                        var emg = MethodGroup as ExtensionMethodGroupExpr;
                        if (emg != null) {
-                               return MethodGroupExpr.CreatePredefined (candidate, candidate.DeclaringType, MethodGroup.Location);
+                               var mg = MethodGroupExpr.CreatePredefined (candidate, candidate.DeclaringType, MethodGroup.Location);
+                               if (candidate.IsGeneric) {
+                                       var targs = new TypeExpression [candidate.Arity];
+                                       for (int i = 0; i < targs.Length; ++i) {
+                                               targs[i] = new TypeExpression (candidate.TypeArguments[i], MethodGroup.Location);
+                                       }
+
+                                       mg.SetTypeArguments (null, new TypeArguments (targs));
+                               }
+
+                               return mg;
                        }
 
                        return MethodGroup;