From e2d4e96fb4929ffe9154cdee17639ebf7c35619b Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Mon, 11 Apr 2016 16:11:34 +0200 Subject: [PATCH] [mcs] Tie-breaking rules are applied also for non-equivalent parameter types. Fixess #40183 --- mcs/mcs/ecore.cs | 29 +++++++++++---- mcs/tests/gtest-optional-36.cs | 66 ++++++++++++++++++++++++++++++++++ mcs/tests/test-933.cs | 22 ++++++++++++ mcs/tests/ver-il-net_4_x.xml | 44 +++++++++++++++++++++++ 4 files changed, 155 insertions(+), 6 deletions(-) create mode 100644 mcs/tests/gtest-optional-36.cs create mode 100644 mcs/tests/test-933.cs diff --git a/mcs/mcs/ecore.cs b/mcs/mcs/ecore.cs index 56c1b2edb88..145f222bdcd 100644 --- a/mcs/mcs/ecore.cs +++ b/mcs/mcs/ecore.cs @@ -4704,8 +4704,14 @@ namespace Mono.CSharp { // for each argument, the conversion to 'ct' should be no worse than // the conversion to 'bt'. - if (result == 2) - return false; + if (result == 2) { + better_at_least_one = false; + + ++j; + while (j < args_count && !args [j++].IsDefaultArgument) ; + + break; + } // for at least one argument, the conversion to 'ct' should be better than // the conversion to 'bt'. @@ -4717,15 +4723,26 @@ namespace Mono.CSharp { return true; // - // Tie-breaking rules are applied only for equivalent parameter types + // LAMESPEC: Tie-breaking rules for not equivalent parameter types // if (!are_equivalent) { // - // LAMESPEC: A candidate with less default parameters is still better when there + // A candidate with no default parameters is still better when there // is no better expression conversion // - if (candidate_pd.Count < best_pd.Count && !candidate_params && best_pd.FixedParameters [j].HasDefaultValue) { - return true; + if (candidate_pd.Count < best_pd.Count) { + if (!candidate_params && !candidate_pd.FixedParameters [j - j].HasDefaultValue) { + return true; + } + } else if (candidate_pd.Count == best_pd.Count) { + if (candidate_params) + return false; + + if (!candidate_pd.FixedParameters [j - 1].HasDefaultValue && best_pd.FixedParameters [j - 1].HasDefaultValue) + return true; + + if (candidate_pd.FixedParameters [j - 1].HasDefaultValue && best_pd.HasParams) + return true; } return false; diff --git a/mcs/tests/gtest-optional-36.cs b/mcs/tests/gtest-optional-36.cs new file mode 100644 index 00000000000..bf9f7d1523b --- /dev/null +++ b/mcs/tests/gtest-optional-36.cs @@ -0,0 +1,66 @@ +using System; + +public class Program +{ + static int Arg (uint a, long b) + { + return 2; + } + + static int Arg (int a, ulong b, int c = 9) + { + return 3; + } + + static int Arg_2 (uint a, long b, params int[] arg) + { + return 2; + } + + static int Arg_2 (int a, ulong b, int c = 0) + { + return 3; + } + + static int Arg_3 (int a, long b, params int[] arg) + { + return 2; + } + + static int Arg_3 (uint a, ulong b, int c = 0, int d = 1, params int[] oo) + { + return 3; + } + + public static int Main () + { + if (Arg (0, 0) != 2) + return 1; + + if (Arg (0, 0, 0) != 3) + return 2; + + if (Arg_2 (0, 0) != 3) + return 3; + + if (Arg_2 (0, 0, 0, 0) != 2) + return 4; + + if (Arg_3 (0, 0) != 2) + return 5; + + if (Arg_3 (0, 0, 0) != 2) + return 6; + + if (Arg_3 (0, 0, 0, 0) != 2) + return 7; + + if (Arg_3 (0, 0, 0, 0, 0) != 2) + return 8; + + if (Arg_3 (0, 0, 0, 0, 0) != 2) + return 9; + + return 0; + } +} diff --git a/mcs/tests/test-933.cs b/mcs/tests/test-933.cs new file mode 100644 index 00000000000..2f076ebd254 --- /dev/null +++ b/mcs/tests/test-933.cs @@ -0,0 +1,22 @@ +using System; + +class X +{ + static int Foo (params X[] p) + { + return 1; + } + + static int Foo (object p) + { + return 0; + } + + static int Main () + { + if (Foo ((X[]) null) != 1) + return 1; + + return 0; + } +} \ No newline at end of file diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index b7054e4b289..21da636a0c5 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -30666,6 +30666,34 @@ + + + + 10 + + + 10 + + + 10 + + + 10 + + + 10 + + + 10 + + + 238 + + + 7 + + + @@ -51945,6 +51973,22 @@ + + + + 10 + + + 10 + + + 29 + + + 7 + + + -- 2.25.1