Skip to content
Open
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
5 changes: 4 additions & 1 deletion CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,10 @@ public override async Task<SyntaxList<StatementSyntax>> VisitSelectBlock(VBSynta
if (!DefinitelyExits(csBlockStatements.LastOrDefault())) {
csBlockStatements.Add(SyntaxFactory.BreakStatement());
}
var list = SingleStatement(SyntaxFactory.Block(csBlockStatements));
var hasLocalDeclaration = csBlockStatements.Any(s => s.IsKind(SyntaxKind.LocalDeclarationStatement));
var list = hasLocalDeclaration
? SingleStatement(SyntaxFactory.Block(csBlockStatements))
: SyntaxFactory.List(csBlockStatements);
sections.Add(SyntaxFactory.SwitchSection(SyntaxFactory.List(labels), list));
}

Expand Down
282 changes: 111 additions & 171 deletions Tests/CSharp/ExpressionTests/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,13 @@ public void Main()
switch (e1)
{
case 0:
{
break;
}
break;
}

switch (e2)
{
case (int)E.A:
{
break;
}
break;
}

}
Expand Down Expand Up @@ -464,16 +460,12 @@ public static void Main()
switch (1)
{
case 1:
{
Console.WriteLine(""a"");
break;
}
Console.WriteLine(""a"");
break;

case var @case when @case == 1:
{
Console.WriteLine(""b"");
break;
}
Console.WriteLine(""b"");
break;

}

Expand Down Expand Up @@ -2039,10 +2031,8 @@ public static void Main()
switch (x)
{
case (int)E.A:
{
Console.WriteLine(""z"");
break;
}
Console.WriteLine(""z"");
break;
}
}
}");
Expand Down Expand Up @@ -2088,26 +2078,18 @@ public void OnLoad(UserInterface? ui)
switch (ui)
{
case object _ when ui is null:
{
activity = 1;
break;
}
activity = 1;
break;
case UserInterface.Spectrum:
{
activity = 2;
break;
}
activity = 2;
break;
case UserInterface.Wisdom:
{
activity = 3;
break;
}
activity = 3;
break;

default:
{
activity = 4;
break;
}
activity = 4;
break;
}
}
}");
Expand Down Expand Up @@ -2206,160 +2188,128 @@ public int OnLoad()
switch (x)
{
case 0:
{
continue;
}
continue;
case 1:
x = 1;
break;
case 2:
return 2;
case 3:
throw new Exception();
case 4:
if (true)
{
x = 1;
break;
x = 4;
}
case 2:
else
{
return 2;
return x;
}
case 3:

break;
case 5:
if (true)
{
throw new Exception();
return x;
}
case 4:
else
{
if (true)
{
x = 4;
}
else
{
return x;
}
x = 5;
}

break;
break;
case 6:
if (true)
{
return x;
}
case 5:
else if (false)
{
if (true)
{
return x;
}
else
{
x = 5;
}

break;
x = 6;
}
case 6:
else
{
if (true)
{
return x;
}
else if (false)
{
x = 6;
}
else
{
return x;
}

break;
return x;
}

break;
case 7:
if (true)
{
if (true)
{
return x;
}

break;
return x;
}

break;
case 8:
if (true)
return x;
break;
case 9:
if (true)
x = 9;
break;
case 10:
if (true)
return x;
else
x = 10;
break;
case 11:
if (true)
x = 11;
else
return x;
break;
case 12:
if (true)
return x;
else
return x;
case 13:
if (true)
{
if (true)
return x;
break;
return x;
}
case 9:
else if (false)
{
if (true)
x = 9;
break;
continue;
}
case 10:
else if (false)
{
if (true)
return x;
else
x = 10;
break;
throw new Exception();
}
case 11:
else if (false)
{
if (true)
x = 11;
else
return x;
break;
}
case 12:
else
{
if (true)
return x;
else
return x;
return x;
}
case 13:
case 14:
if (true)
{
if (true)
{
return x;
}
else if (false)
{
continue;
}
else if (false)
{
throw new Exception();
}
else if (false)
{
break;
}
else
{
return x;
}
return x;
}
case 14:
else if (false)
{
return x;
}
else if (false)
{
if (true)
{
return x;
}
else if (false)
{
return x;
}
else if (false)
{
break;
}

break;
}

break;

default:
if (true)
{
return x;
}
else
{
if (true)
{
return x;
}
else
{
return x;
}
return x;
}
}
}
Expand Down Expand Up @@ -2402,31 +2352,21 @@ public void S()
switch (o)
{
case var @case when Operators.ConditionalCompareObjectEqual(@case, 1, false):
{
j = 1;
break;
}
j = 1;
break;
case var case1 when Operators.ConditionalCompareObjectEqual(case1, 2, false):
{
j = 2;
break;
}
j = 2;
break;
case var case2 when Operators.ConditionalCompareObjectLessEqual(3, case2, false) && Operators.ConditionalCompareObjectLessEqual(case2, 4, false):
{
j = 3;
break;
}
j = 3;
break;
case var case3 when Operators.ConditionalCompareObjectGreater(case3, 4, false):
{
j = 4;
break;
}
j = 4;
break;

default:
{
j = -1;
break;
}
j = -1;
break;
}
}
}
Expand Down
Loading
Loading