Skip to content

Commit b0e53ca

Browse files
committed
Fix #1244: Avoid unnecessary code blocks in switch case sections
Only wrap switch case statements in a Block when a local variable declaration is present. Otherwise emit statements directly, eliminating the extra level of braces and indentation. https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
1 parent 76b1e25 commit b0e53ca

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,10 @@ public override async Task<SyntaxList<StatementSyntax>> VisitSelectBlock(VBSynta
885885
if (!DefinitelyExits(csBlockStatements.LastOrDefault())) {
886886
csBlockStatements.Add(SyntaxFactory.BreakStatement());
887887
}
888-
var list = SingleStatement(SyntaxFactory.Block(csBlockStatements));
888+
var hasLocalDeclaration = csBlockStatements.Any(s => s.IsKind(SyntaxKind.LocalDeclarationStatement));
889+
var list = hasLocalDeclaration
890+
? SingleStatement(SyntaxFactory.Block(csBlockStatements))
891+
: SyntaxFactory.List(csBlockStatements);
889892
sections.Add(SyntaxFactory.SwitchSection(SyntaxFactory.List(labels), list));
890893
}
891894

0 commit comments

Comments
 (0)