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

Name clashes #48

Open
GrahamTheCoder opened this issue Aug 9, 2020 · 1 comment
Open

Name clashes #48

GrahamTheCoder opened this issue Aug 9, 2020 · 1 comment

Comments

@GrahamTheCoder
Copy link

Input

public class ClashingNames
{
    private string ab;

    void Test()
    {
        object aB = 5;
        int Ab = 7;
    }

    void Test2(int ab)
    {
        object aB = 5;
        int AB =  6;
        string s = nameof(AB);
        string s2 = nameof(ab);
    }
}

Expected output (from https://codeconverter.icsharpcode.net/)

Public Class x
    Private ab As String

    Private Sub Test()
        Dim lAB As Object = 5
        Dim Ab As Integer = 7
    End Sub

    Private Sub Test2(ByVal ab As Integer)
        Dim lAB As Object = 5
        Dim lAB1 As Integer = 6
        Dim s As String = NameOf(lAB1)
        Dim s2 As String = NameOf(ab)
    End Sub
End Class

Actual output

Option Compare Text
Option Explicit On
Option Infer Off
Option Strict On


Public Class x
    Private _ab As String

    Private Sub Test()
        Dim aB As Object = 5
        Dim Ab As Integer = 7
    End Sub

    Private Sub Test2(_ab As Integer)
        Dim aB As Object = 5
        Dim AB As Integer = 6
        Dim s As String = NameOf(AB)
        Dim s2 As String = NameOf(_ab)
    End Sub


End Class

Compilation errors

error BC30288: Local variable 'Ab' is already declared in the current block.
error BC30288: Local variable 'AB' is already declared in the current block.
  • Note: Obviously this is an extreme example. I did see the existing renaming code add "_Renamed" for one variable in another case I tried, so it does sometimes work.

Possible solution

After you forked from https://github.com/icsharpcode/CodeConverter/ I implemented a very robust and isolated way of renaming to avoid this issue. All you need to do is call this method on the project object just before you convert:
https://github.com/icsharpcode/CodeConverter/blob/master/CodeConverter/VB/ClashingMemberRenamer.cs#L21

It's not currently a public class, but I could make it public if you want to just use it via nuget rather than copying/converting?

@paul1956
Copy link
Owner

@GrahamTheCoder I fixed in converter 3.4.6.2. There may still be issues in full project conversion. I added solution converter which works very well because I pick up all the Types and I now convert gRPC projects which require parts in to stay in C# but be referenced by VB. I also do Async ForEach and many Patterns I have a solution for Ref Returns but not sure how to do an automatic conversion that doesn't break ByRef in general. Biggest issue in any kind of Merge is mine in in VB and yours is in C#.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants