[mcs] Update better conversion tie breaking rules to cover candidate with longer...
authorMarek Safar <marek.safar@gmail.com>
Fri, 11 Nov 2016 14:52:44 +0000 (15:52 +0100)
committerMarek Safar <marek.safar@gmail.com>
Fri, 11 Nov 2016 14:55:13 +0000 (15:55 +0100)
mcs/mcs/ecore.cs
mcs/tests/gtest-optional-40.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index ad4faf3ce242d67a81f170f9c4620b757e438fac..8475a9e489428c0d98d91267b7b40954a54be3c2 100644 (file)
@@ -4781,12 +4781,18 @@ namespace Mono.CSharp {
 
                                //
                                // A candidate with no default parameters is still better when there
-                               // is no better expression conversion
+                               // is no better expression conversion and does not have more parameters
                                //
                                if (candidate_pd.Count < best_pd.Count) {
-                                       if (!candidate_params && !candidate_pd.FixedParameters [j - 1].HasDefaultValue) {
+                                       if (candidate_params)
+                                               return false;
+                                       
+                                       if (!candidate_pd.FixedParameters [j - 1].HasDefaultValue)
                                                return true;
-                                       }
+
+                                       if (best_pd.FixedParameters [j].HasDefaultValue)
+                                               return true;
+                                       
                                } else if (candidate_pd.Count == best_pd.Count) {
                                        if (candidate_params)
                                                return false;
diff --git a/mcs/tests/gtest-optional-40.cs b/mcs/tests/gtest-optional-40.cs
new file mode 100644 (file)
index 0000000..e554fa7
--- /dev/null
@@ -0,0 +1,19 @@
+using System;
+
+internal class Program
+{
+       public static void Main ()
+       {
+               AttributeOrDefault ("firstItem", null); 
+       }
+       
+       public static string AttributeOrDefault (string attribute, string defaultValue = null)
+       {
+               return "";
+       }
+
+       public static string AttributeOrDefault (string attribute, bool? klass, string defaultValue = null)
+       {
+               throw new ApplicationException ();
+       }
+}
index f9c8f8b2465c7c00ddc1831c311422c9785ad594..7df1a90869f6c5f7214af565f80b61175578bc42 100644 (file)
       </method>
     </type>
   </test>
+  <test name="gtest-optional-40.cs">
+    <type name="Program">
+      <method name="Void Main()" attrs="150">
+        <size>14</size>
+      </method>
+      <method name="System.String AttributeOrDefault(System.String, System.String)" attrs="150">
+        <size>14</size>
+      </method>
+      <method name="System.String AttributeOrDefault(System.String, System.Nullable`1[System.Boolean], System.String)" attrs="150">
+        <size>7</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-partial-01.cs">
     <type name="B`1[U]">
       <method name="Void .ctor()" attrs="6278">