dotnet/roslyn

IntelliSense uses wrong types for lambdas passed using named parameters

Open

#38,775 建立於 2019年9月19日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)C# (20,414 star) (4,257 fork)batch import
Area-CompilersBugDeveloper CommunityIDE-IntelliSensehelp wanted

描述

This issue has been moved from a ticket on Developer Community.


If you have a method which accepts multiple lambdas as arguments and use named parameters to pass the lambdas in a different order, IntelliSense within a passed lambda body will use the wrong types for completion against the lambda's parameters in the lambda body. That was a big sentence.

void MethodWithMultipleLambdaArguments(
    Action<(int x, int y)> action,
    Action<IEnumerable<string>> checkThings = null)
{
    checkThings?.Invoke(new[]
    {
            "a",
            "b",
        });
    action((1, 2));
}

public void DoSomething()
{
    MethodWithMultipleLambdaArguments(checkThings: things =>
    {
        things.«here»
    }, action: pair =>
    {

    });
}

If you take the above code in a C# class in Visual Studio, remove the “«here»”, and then try completion from where “«here»” was, you will see something like this:

autocompletion for action’s parameter shown when completing against checkThings’s parameter

I think that there is something like incomplete type information being calculated because the lambda has a syntax error, preventing it from being fully resolved by the C# compiler. However, in this case, with named parameters, and a limited number of possible matching method overrides (in this case, exactly one), the compiler should have enough information to calculate the correct types for the lambda’s parameter.


Original Comments

Visual Studio Feedback System on 9/16/2019, 03:48 AM:

Nathan Phillip Brink (binki) on 9/16/2019, 06:43 AM:


Original Solutions

(no solutions)

貢獻者指南