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

VB -> C#: Compiler Error CS0826 (no best type found for implicitly typed array) #713

Closed
chtenb opened this issue Mar 28, 2021 · 4 comments
Closed
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@chtenb
Copy link

chtenb commented Mar 28, 2021

I get this error a lot in all kinds of situations. It seems to me that the C# code should use an explicit type as default, and only if we are sure that the type can be derived maybe use an implicit type.

Input code

{}

Erroneous output

new [] {}

Expected output

new ExplicitType[] {}

Details

  • Product in use: VS extension
    image
@chtenb chtenb added the VB -> C# Specific to VB -> C# conversion label Mar 28, 2021
@GrahamTheCoder
Copy link
Member

Thanks for the report. {} is treated slightly differently in different contexts, could you give at least the whole statement?

For example:

Public Class C
    Public Sub M()
        M({})
    End Sub

    Public Sub M(x As Integer())
        Dim y As CompletelyMadeUpType() = {}
    End Sub
End Class

(correctly as far as I can see) converts to

using System;

public partial class C
{
    public void M()
    {
        M(Array.Empty<int>());
    }

    public void M(int[] x)
    {
        var y = Array.Empty<CompletelyMadeUpType>();
    }
}

@chtenb
Copy link
Author

chtenb commented Mar 28, 2021

If Validate(name, par, {"foo"}, {}, Stuff) Then
'...
End If

with the following definition

Private Function Validate(x As String, y As IEnumerable(Of String), z As IEnumerable(Of String), w As IEnumerable(Of Int16), Errors As String) As Boolean
'...
End Function

@GrahamTheCoder
Copy link
Member

Thanks!

@chtenb
Copy link
Author

chtenb commented May 4, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

2 participants