提交 ecb97d46 编写于 作者: A AlekseyTs

Merge pull request #4645 from AlekseyTs/Issue4424

Adjust implementation of OverloadResolution.GetParameterCounts to account for a situation when params parameter is used through a named argument.
......@@ -1551,8 +1551,18 @@ private static TypeSymbol GetParameterType(int argIndex, MemberAnalysisResult re
{
if (arguments.Count < declaredParameterCount)
{
// params parameter isn't used (see ExpressionBinder::TryGetExpandedParams in the native compiler)
parametersUsedIncludingExpansionAndOptional = declaredParameterCount - 1;
ImmutableArray<int> argsToParamsOpt = m.Result.ArgsToParamsOpt;
if (argsToParamsOpt.IsDefaultOrEmpty || !argsToParamsOpt.Contains(declaredParameterCount - 1))
{
// params parameter isn't used (see ExpressionBinder::TryGetExpandedParams in the native compiler)
parametersUsedIncludingExpansionAndOptional = declaredParameterCount - 1;
}
else
{
// params parameter is used by a named argument
parametersUsedIncludingExpansionAndOptional = declaredParameterCount;
}
}
else
{
......
......@@ -7894,6 +7894,32 @@ public static void Main()
);
}
[Fact, WorkItem(4424, "https://github.com/dotnet/roslyn/issues/4424")]
public void TieBreakOnNumberOfDeclaredParameters_06()
{
string source1 = @"
class Test
{
static void Fn(string x = """", string y = """", params object[] p)
{
System.Console.WriteLine(1);
}
static void Fn(string x, params object[] p)
{
System.Console.WriteLine(2);
}
static void Main()
{ Fn(""Hello"", p: ""World""); }
}
";
var compilation = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugExe);
CompileAndVerify(compilation, expectedOutput: @"2");
}
[Fact, WorkItem(1099752, "DevDiv"), WorkItem(2291, "https://github.com/dotnet/roslyn/issues/2291")]
public void BetterErrorMessage_01()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册