Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CodeConverter/CSharp/CommonConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ private async Task<ExpressionSyntax> IncreaseArrayUpperBoundExpressionAsync(VBSy
&& convertedExpression.SkipIntoParens() is CSSyntax.BinaryExpressionSyntax bExp && bExp.IsKind(CSSyntaxKind.SubtractExpression))
return bExp.Left;

if (convertedExpression is CSSyntax.ConditionalExpressionSyntax ce) {
convertedExpression = SyntaxFactory.ParenthesizedExpression(convertedExpression);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general the codebase is easier to reason about if you avoid using the shape of the output to influence further output. This is simple enough for now though, so let's go with it!


return SyntaxFactory.BinaryExpression(
CSSyntaxKind.SubtractExpression,
convertedExpression, SyntaxFactory.Token(CSSyntaxKind.PlusToken), SyntaxFactory.LiteralExpression(CSSyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(1)));
Expand Down
20 changes: 20 additions & 0 deletions Tests/CSharp/ExpressionTests/AccessExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,26 @@ public string[][] GetStringsFromAmbiguous(int amb)
}");
}

[Fact]
public async Task TernaryArrayIndexerAsync()
{
await TestConversionVisualBasicToCSharpAsync(@"Public Class A
Public Sub Test()
Dim i as integer = 0
Dim a(If(i = 1, 2, 3)) as string
End Sub
End Class", @"
public partial class A
{
public void Test()
{
int i = 0;
var a = new string[(i == 1 ? 2 : 3) + 1];
}
}");
}


[Fact]
public async Task ElementAtOrDefaultIndexingAsync()
{
Expand Down
Loading