dotnet/roslyn

Confusing error message for overloaded generic delegate-accepting method

Open

#8.603 aberto em 11 de fev. de 2016

Ver no GitHub
 (1 comment) (1 reaction) (1 assignee)C# (4.257 forks)batch import
Area-CompilersBugConcept-Diagnostic Clarityhelp wanted

Métricas do repositório

Stars
 (20.414 stars)
Métricas de merge de PR
 (Mesclagem média 6d 17h) (256 fundiu PRs em 30d)

Description

I have the following code:

using System;

class Program
{
    static void Main()
    {
        M(x => { });
    }

    static void M(string s)
    {
    }

    static void M<T>(Action<T> a)
    {
    }
}

It produces the following error:

CS1660 Cannot convert lambda expression to type 'string' because it is not a delegate type

I think that a human can clearly see that the code is attempting to call the delegate-accepting overload, but is missing a type argument (M<int>(x => { });) or explicit parameter type (M((int x) => { });).

But the compiler shows error message that's related to the first (string-accepting) overload, which I think is confusing.

Guia do colaborador