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#: Cleaner output for string comparison #500

Open
mrmonday opened this issue Jan 15, 2020 · 1 comment
Open

VB -> C#: Cleaner output for string comparison #500

mrmonday opened this issue Jan 15, 2020 · 1 comment
Labels

Comments

@mrmonday
Copy link
Contributor

@mrmonday mrmonday commented Jan 15, 2020

When comparing against a string literal in VB, the C# output could be cleaner.

Input code

Public Class VisualBasicClass

    Sub Foo()
        Dim x = ""
        Dim y = x = "something"
    End Sub

End Class

Erroneous output

public partial class VisualBasicClass
{
    public void Foo()
    {
        string x = "";
        bool y = (x ?? "") == "something";
    }
}

Expected output

public partial class VisualBasicClass
{
    public void Foo()
    {
        string x = "";
        bool y = x == "something";
    }
}

Details

Version 7.6.0.0

@mrmonday mrmonday added the VB -> C# label Jan 15, 2020
@GrahamTheCoder

This comment has been minimized.

Copy link
Member

@GrahamTheCoder GrahamTheCoder commented Jan 16, 2020

Good plan. VisualBasicEqualityComparison is a bit of a mess and I think actually misses a couple of cases currently, so feel free to move things around. I assume the rule you mean to add is:
"If either side is a non empty literal (and it isn't generating a string.compare call), there's no need to coalesce"

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.