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#: Missing conversion for array index assignment #365

Closed
mrmonday opened this issue Aug 21, 2019 · 3 comments
Closed

VB -> C#: Missing conversion for array index assignment #365

mrmonday opened this issue Aug 21, 2019 · 3 comments
Labels
compilation error A bug where the converted output won't compile good first issue VB -> C# Specific to VB -> C# conversion

Comments

@mrmonday
Copy link
Contributor

Input code

Module Module1
    Sub Main()
        Dim x As New ArrayList
        x.Add("a")

        Dim xs(1) As String

        xs(0) = x(0)

    End Sub
End Module

Erroneous output

namespace ConsoleApp10
{
    static class Module1
    {
        public static void Main()
        {
            ArrayList x = new ArrayList();
            x.Add("a");

            string[] xs = new string[2];

            xs[0] = x[0];
        }
    }
}

Expected output

namespace ConsoleApp10
{
    static class Module1
    {
        public static void Main()
        {
            ArrayList x = new ArrayList();
            x.Add("a");

            string[] xs = new string[2];

            xs[0] = Conversions.ToString(x[0]);
        }
    }
}

Details

Version in use: master @ 2483369

@GrahamTheCoder GrahamTheCoder added compilation error A bug where the converted output won't compile VB -> C# Specific to VB -> C# conversion labels Aug 21, 2019
@BrianFreemanAtlanta
Copy link
Contributor

Attempting to look into this one. When I get into AnalyzeConversion the typeInfo/vbType = "ErrorType ?" Not sure if additional information is needed on the conversion or add a case for the ErrorType or take another tack.
If you'd like me to do a pull request with the test case in it I can do that.

@GrahamTheCoder
Copy link
Member

GrahamTheCoder commented Oct 16, 2019

If you see ErrorType or ErrorSymbol it generally means the compilation had errors.
If you look at _semanticModel.GetDiagnostics() you'll be able to see them.
In this case, adding an import should cover it:

Imports System.Collections

Public Module Module1
	Sub Main()
        Dim x As New ArrayList
        x.Add("a")

        Dim xs(1) As String

        xs(0) = x(0)

    End Sub
End Module

Other stuff:

  • There's also a _showCompilationErrors flag I use for showing errors in the test output, but I recently broke it. It'll be fixed again as part of Enable checks that test conversion code compiles #60
  • Ideally that System.Collections import would have been automatically added for all conversions since it's a common one (and unused imports get removed at the end). Things like that should go into the list here: https://github.com/icsharpcode/CodeConverter/blob/master/ICSharpCode.CodeConverter/Util/VisualBasicCompiler.cs#L58 which if it "just works" would probably be a better fix rather than changing the test. There's a list of all .NET framework namespaces here: I'd be tempted to add literally all of them...though that would cause potential ambiguities with existing using statements (or each other), so it'd probably be better to either investigate which contain clashing type names (with a bit of reflection investigation), or just pick ones from that list that we've actually ever seen used. I wish I could crawl github for the most commonly used using statements...maybe just add the one for now and we'll do more on this another time.

@GrahamTheCoder
Copy link
Member

Generally it's also worth just having a solution with a VB and a CS project open alongside the code converter for checking syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compilation error A bug where the converted output won't compile good first issue VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

3 participants