Skip to content

Commit

Permalink
BinaryConditional's first expression isn't always boolean - fixes #1038
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamTheCoder committed Oct 17, 2023
1 parent fd6e10a commit 2314120
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* Support CData [#1032](https://github.com/icsharpcode/CodeConverter/issues/1032)
* Use verbatim strings for strings containing newlines
* Fix clashing symbol renamer for Enum types [#1035](https://github.com/icsharpcode/CodeConverter/issues/1035)
* Convert nullable operators within a binary condition expression [#1038](https://github.com/icsharpcode/CodeConverter/issues/1038)

### C# -> VB

Expand Down
1 change: 0 additions & 1 deletion CodeConverter/CSharp/VbSyntaxNodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public static bool AlwaysHasBooleanTypeInCSharp(this VBSyntax.ExpressionSyntax v
parent is VBSyntax.IfStatementSyntax ifStatement && ifStatement.Condition == vbNode ||
parent is VBSyntax.ElseIfStatementSyntax elseIfStatement && elseIfStatement.Condition == vbNode ||
parent is VBSyntax.TernaryConditionalExpressionSyntax ternary && ternary.Condition == vbNode ||
parent is VBSyntax.BinaryConditionalExpressionSyntax binary && binary.FirstExpression == vbNode ||
parent is VBSyntax.WhereClauseSyntax;
}
}
19 changes: 19 additions & 0 deletions Tests/CSharp/TypeCastTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,25 @@ private void Test()
}");
}

[Fact]
public async Task RetainNullableBoolWhenNeededAsync()
{
await TestConversionVisualBasicToCSharpAsync(
@"Class Class1
Function F(a As Net.IPAddress) As Boolean
Return If(a?.ScopeId = 0, True)
End Function
End Class",
@"
internal partial class Class1
{
public bool F(System.Net.IPAddress a)
{
return ((a?.ScopeId) is { } arg1 ? arg1 == 0 : (bool?)null) ?? true;
}
}");
}

[Fact]
public async Task TestNullableBoolConversionsAsync()
{
Expand Down

0 comments on commit 2314120

Please sign in to comment.