Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show only exact error message when calling a method overload with named params #42938

Open
VBAndCs opened this issue Mar 31, 2020 · 0 comments
Open
Labels
Area-Compilers Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings.

Comments

@VBAndCs
Copy link

VBAndCs commented Mar 31, 2020

I used named params to call a specific String.Join overload:

Dim x As New List(Of String) From {"a", "b", "c"}
Dim y = String.Join(separator:=$", ", value:=x, startIndex:=1, count:=x.Count - 1)

I missed a cast from List(Of string) to String(), so I expected to get the error:

Value of type 'List(Of String)' cannot be converted to 'String()'. Are you missing a cast?

but instead I got this too long user unfriendly error message:

Overload resolution failed because no accessible 'Join' can be called with these arguments: 'Public Shared Overloads Function Join(separator As Char, ParamArray values As Object()) As String': 'value' is not a method parameter. 'Public Shared Overloads Function Join(separator As Char, ParamArray values As Object()) As String': 'startIndex' is not a method parameter. 'Public Shared Overloads Function Join(separator As Char, ParamArray values As Object()) As String': 'count' is not a method parameter. 'Public Shared Overloads Function Join(separator As Char, ParamArray value As String()) As String': Named argument cannot match a ParamArray parameter. 'Public Shared Overloads Function Join(separator As Char, ParamArray value As String()) As String': 'startIndex' is not a method parameter. 'Public Shared Overloads Function Join(separator As Char, ParamArray value As String()) As String': 'count' is not a method parameter. 'Public Shared Overloads Function Join(separator As Char, value As String(), startIndex As Integer, count As Integer) As String': Value of type 'List(Of String)' cannot be converted to 'String()'. 'Public Shared Overloads Function Join(separator As String, ParamArray values As Object()) As String': 'value' is not a method parameter. 'Public Shared Overloads Function Join(separator As String, ParamArray values As Object()) As String': 'startIndex' is not a method parameter. 'Public Shared Overloads Function Join(separator As String, ParamArray values As Object()) As String': 'count' is not a method parameter. 'Public Shared Overloads Function Join(separator As String, ParamArray value As String()) As String': Named argument cannot match a ParamArray parameter. 'Public Shared Overloads Function Join(separator As String, ParamArray value As String()) As String': 'startIndex' is not a method parameter. 'Public Shared Overloads Function Join(separator As String, ParamArray value As String()) As String': 'count' is not a method parameter. 'Public Shared Overloads Function Join(separator As String, value As String(), startIndex As Integer, count As Integer) As String': Value of type 'List(Of String)' cannot be converted to 'String()'. Extension method 'Public Function Join(Of TInner, TKey, TResult)(inner As IEnumerable(Of TInner), outerKeySelector As Func(Of Char, TKey), innerKeySelector As Func(Of TInner, TKey), resultSelector As Func(Of Char, TInner, TResult)) As IEnumerable(Of TResult)' defined in 'Enumerable': 'separator' is not a method parameter. Extension method 'Public Function Join(Of TInner, TKey, TResult)(inner As IEnumerable(Of TInner), outerKeySelector As Func(Of Char, TKey), innerKeySelector As Func(Of TInner, TKey), resultSelector As Func(Of Char, TInner, TResult)) As IEnumerable(Of TResult)' defined in 'Enumerable': 'value' is not a method parameter. Extension method 'Public Function Join(Of TInner, TKey, TResult)(inner As IEnumerable(Of TInner), outerKeySelector As Func(Of Char, TKey), innerKeySelector As Func(Of TInner, TKey), resultSelector As Func(Of Char, TInner, TResult)) As IEnumerable(Of TResult)' defined in 'Enumerable': 'startIndex' is not a method parameter. Extension method 'Public Function Join(Of TInner, TKey, TResult)(inner As IEnumerable(Of TInner), outerKeySelector As Func(Of Char, TKey), innerKeySelector As Func(Of TInner, TKey), resultSelector As Func(Of Char, TInner, TResult)) As IEnumerable(Of TResult)' defined in 'Enumerable': 'count' is not a method parameter. Extension method 'Public Function Join(Of TInner, TKey, TResult)(inner As IEnumerable(Of TInner), outerKeySelector As Func(Of Char, TKey), innerKeySelector As Func(Of TInner, TKey), resultSelector As Func(Of Char, TInner, TResult)) As IEnumerable(Of TResult)' defined in 'Enumerable': Argument not specified for parameter 'inner'. Extension method 'Public Function Join(Of TInner, TKey, TResult)(inner As IEnumerable(Of TInner), outerKeySelector As Func(Of Char, TKey), innerKeySelector As Func(Of TInner, TKey), resultSelector As Func(Of Char, TInner, TResult)) As IEnumerable(Of TResult)' defined in 'Enumerable': Argument not specified for parameter 'outerKeySelector'. Extension method 'Public Function Join(Of TInner, TKey, TResult)(inner As IEnumerable(Of TInner), outerKeySelector As Func(Of Char, TKey), innerKeySelector As Func(Of TInner, TKey), resultSelector As Func(Of Char, TInner, TResult)) As IEnumerable(Of TResult)' defined in 'Enumerable': Argument not specified for parameter 'innerKeySelector'. Extension method 'Public Function Join(Of TInner, TKey, TResult)(inner As IEnumerable(Of TInner), outerKeySelector As Func(Of Char, TKey), innerKeySelector As Func(Of TInner, TKey), resultSelector As Func(Of Char, TInner, TResult)) As IEnumerable(Of TResult)' defined in 'Enumerable': Argument not specified for parameter 'resultSelector'.

Which contains the true error some where in the heap.
This sort of long misleading overload resolution failure message wastes me a lot of time every time. After all, there is no resolution in this full named argument call. It is just a direct call for an existing overload, so it should be treated as a normal call to a non-overloaded method, and show the exact error message.
This could be relevant to #42857

@jinujoseph jinujoseph added Area-Compilers Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. labels Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings.
Projects
None yet
Development

No branches or pull requests

2 participants