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#: null coalescing operator not playing well with boolean expressions #712

Closed
chtenb opened this issue Mar 28, 2021 · 0 comments
Closed
Labels
compilation error A bug where the converted output won't compile VB -> C# Specific to VB -> C# conversion

Comments

@chtenb
Copy link

chtenb commented Mar 28, 2021

Input code

If Not String.IsNullOrWhiteSpace(Var1) AndAlso Not (Var1?.StartsWith("{"c) AndAlso Var1?.EndsWith("}"c)) Then
    ' ...
End If
If Not String.IsNullOrWhiteSpace(Var2) AndAlso Not Var2?.StartsWith(">") Then
    ' ...
End If

Erroneous output

error CS0019: Operator '&&' cannot be applied to operands of type 'bool?' and 'bool?'
error CS0019: Operator '&&' cannot be applied to operands of type 'bool' and 'bool?
if ((!string.IsNullOrWhiteSpace(Var1) && !((Var1?.StartsWith(Conversions.ToString('{'))) && (Var1?.EndsWith(Conversions.ToString('}'))))) == true)
{
    //...
}
if ((!string.IsNullOrWhiteSpace(Var2) && !(Var2?.StartsWith(">"))) == true)
{
    //...
}

Expected output

if (!string.IsNullOrWhiteSpace(Var1) && !(Var1?.StartsWith("{") ?? false) && (Var1?.EndsWith("}") ?? false))
{
    //...
}
if (!string.IsNullOrWhiteSpace(Var2) && !(Var2?.StartsWith(">") ?? false))
{
    //...
}

Details

  • Product in use: VS extension
    image
@chtenb chtenb added the VB -> C# Specific to VB -> C# conversion label Mar 28, 2021
@GrahamTheCoder GrahamTheCoder added the compilation error A bug where the converted output won't compile label Jun 22, 2021
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 VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

2 participants