dotnet/roslyn

IntelliSense uses wrong types for lambdas passed using named parameters

開放

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

 (3 則留言) (0 個反應) (0 位負責人)C# (4,257 個分叉)batch import
Area-CompilersBugDeveloper CommunityIDE-IntelliSensehelp wanted

倉庫指標

星標
 (20,414 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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)

貢獻者指南