Skip to content

Commit

Permalink
Avoid repeated break caused by explicit Exit Select - fixes #433
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamTheCoder committed Jan 19, 2020
1 parent 395e31e commit afaf706
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* First effort converting some Xml Member Access
* Avoid adding new keyword when not allowed/required [#504](https://github.com/icsharpcode/CodeConverter/issues/504)
* Avoid evaluating Select Case expression multiple times in some cases where it may be non-deterministic or have side effects [#323](https://github.com/icsharpcode/CodeConverter/issues/323)
* Avoid repeated redundant break statement caused by explicit Exit Select [#433](https://github.com/icsharpcode/CodeConverter/issues/433)

### C# -> VB

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ public override async Task<SyntaxList<StatementSyntax>> VisitSelectBlock(VBSynta

var csBlockStatements = (await ConvertStatements(block.Statements)).ToList();
if (csBlockStatements.LastOrDefault()
?.IsKind(SyntaxKind.ReturnStatement) != true) {
?.IsKind(SyntaxKind.ReturnStatement, SyntaxKind.BreakStatement) != true) {
csBlockStatements.Add(SyntaxFactory.BreakStatement());
}
var list = SingleStatement(SyntaxFactory.Block(csBlockStatements));
Expand Down
27 changes: 27 additions & 0 deletions Tests/CSharp/StatementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,33 @@ public void DoesNotThrow()
}");
}

[Fact]
public async Task SelectCaseWithExplicitExit()
{
await TestConversionVisualBasicToCSharpWithoutComments(@"Class A
Public Function Add(ByVal x As Integer) As Integer
Select Case x
Case 1
Exit Select
End Select
Return 3
End Function
End Class", @"internal partial class A
{
public int Add(int x)
{
switch (x)
{
case 1:
{
break;
}
}
return 3;
}
}");
}

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

0 comments on commit afaf706

Please sign in to comment.