[mcs] Fix betterness of candidates with optional parameters against unexpanded params...
authorMarek Safar <marek.safar@gmail.com>
Tue, 7 Apr 2015 15:55:15 +0000 (17:55 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 7 Apr 2015 16:26:34 +0000 (18:26 +0200)
mcs/mcs/ecore.cs
mcs/tests/gtest-optional-09.cs
mcs/tests/ver-il-net_4_5.xml

index d7d370893c6af08c8361f1596be6794f3f14533e..5965fb53e9df360e4737c43d3af530192562317d 100644 (file)
@@ -4727,6 +4727,9 @@ namespace Mono.CSharp {
                                var cand_param = candidate_pd.FixedParameters [j];
                                var best_param = best_pd.FixedParameters [j];
 
+                               if (cand_param.HasDefaultValue != best_param.HasDefaultValue)
+                                       return cand_param.HasDefaultValue;
+
                                if (candidate_pd.Count == best_pd.Count) {
                                        //
                                        // LAMESPEC:
@@ -4734,8 +4737,6 @@ namespace Mono.CSharp {
                                        // 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 cand_param.HasDefaultValue;
 
                                        if (cand_param.HasDefaultValue) {
                                                ++j;
@@ -4749,8 +4750,7 @@ namespace Mono.CSharp {
                                        // void Foo (string s, int i = 0) <-> Foo (string s, byte i = 0)
                                        // void Foo (string s, params int[]) <-> Foo (string s, params byte[])
                                        //
-                                       if (cand_param.HasDefaultValue && best_param.HasDefaultValue)
-                                               return false;
+                                       return false;
                                }
 
                                break;
index cfbe860a7dc9e52dc174bc43b2879ecf1843a62c..7117ab291e7ce6b4fed42288979c4a60936c1279 100644 (file)
@@ -59,20 +59,30 @@ public class Program
 
        static int Test_6 (params object[] o)
        {
-               return 0;
+               return 1;
        }
 
        static int Test_6 (int i = 1, params object[] a)
        {
-               return 1;
+               return 0;
        }
 
        static int Test_7 (bool b, params object[] o)
        {
-               return 0;
+               return 1;
        }
 
        static int Test_7 (bool b, int i = 1, params object[] a)
+       {
+               return 0;
+       }
+
+       static int Test_8 (Type t, bool b = false, int x = 0)
+       {
+               return 0;
+       }
+
+       static int Test_8 (Type t, params int[] x)
        {
                return 1;
        }
@@ -100,6 +110,9 @@ public class Program
                if (Test_7 (false) != 0)
                        return 7;
 
+               if (Test_8 (typeof (bool)) != 0)
+                       return 8;
+
                Console.WriteLine ("ok");
                return 0;
        }
index f7df26864bdc6ed4245f1d853291e536e3f4ac71..ef04802a541af22ec595a703b14f2d5f3eb32c97 100644 (file)
         <size>10</size>
       </method>
       <method name="Int32 Main()" attrs="150">
-        <size>161</size>
+        <size>192</size>
       </method>
       <method name="Void .ctor()" attrs="6278">
         <size>7</size>
       </method>
+      <method name="Int32 Test_8(System.Type, Boolean, Int32)" attrs="145">
+        <size>10</size>
+      </method>
+      <method name="Int32 Test_8(System.Type, Int32[])" attrs="145">
+        <size>10</size>
+      </method>
     </type>
   </test>
   <test name="gtest-optional-10.cs">