[mcs] Fix betterness logic for default vs params parameters. Fixes #19754
authorMarek Safar <marek.safar@gmail.com>
Wed, 28 May 2014 15:59:47 +0000 (17:59 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 28 May 2014 15:59:47 +0000 (17:59 +0200)
mcs/mcs/ecore.cs
mcs/tests/gtest-optional-31.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_5.xml

index 5fb9b84aba7b307868677a8bee213572e59a586a..86c7931f13abbb6cc31055bdc6eb2339ccbce2c2 100644 (file)
@@ -4485,11 +4485,11 @@ namespace Mono.CSharp {
                                        //
                                        // LAMESPEC:
                                        //
-                                       // void Foo (params int[]) is better than void Foo (int i = 0) for Foo ()
+                                       // void Foo (int i = 0) is better than void Foo (params int[]) for Foo ()
                                        // void Foo (string[] s, string value = null) is better than Foo (string s, params string[]) for Foo (null) or Foo ()
                                        //
                                        if (cand_param.HasDefaultValue != best_param.HasDefaultValue)
-                                               return !candidate_params;
+                                               return cand_param.HasDefaultValue;
 
                                        if (cand_param.HasDefaultValue) {
                                                ++j;
diff --git a/mcs/tests/gtest-optional-31.cs b/mcs/tests/gtest-optional-31.cs
new file mode 100644 (file)
index 0000000..9e7158a
--- /dev/null
@@ -0,0 +1,21 @@
+using System;
+
+class Test
+{
+       public static int M (bool b = false)
+       {
+               Console.WriteLine ("PASS");
+               return 0;
+       }
+
+       public static int M (params string[] args)
+       {
+               Console.WriteLine ("FAIL");
+               return 1;
+       }
+       
+       public static int Main ()
+       {
+               return M ();
+       }
+}
index d74076160cf58bc95eb290a4e4f2a167becb5bdb..4e3600db73f56ae524f5f367b243bd552fa5d4b4 100644 (file)
       </method>\r
     </type>\r
   </test>\r
+  <test name="gtest-optional-31.cs">\r
+    <type name="Test">\r
+      <method name="Int32 M(Boolean)" attrs="150">\r
+        <size>20</size>\r
+      </method>\r
+      <method name="Int32 M(System.String[])" attrs="150">\r
+        <size>20</size>\r
+      </method>\r
+      <method name="Int32 Main()" attrs="150">\r
+        <size>15</size>\r
+      </method>\r
+      <method name="Void .ctor()" attrs="6278">\r
+        <size>7</size>\r
+      </method>\r
+    </type>\r
+  </test>\r
   <test name="gtest-partial-01.cs">\r
     <type name="B`1[U]">\r
       <method name="Void .ctor()" attrs="6278">\r