Skip to content

Commit 62b9094

Browse files
Fix switch statements with only default
If a switch statement only has a "default" case it will be replaced with an expression that is just the default body and a break label.
1 parent ad4544e commit 62b9094

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/PSLambda/CompileVisitor.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,15 @@ public object VisitSwitchStatement(SwitchStatementAst switchStatementAst)
802802
{
803803
using (_loops.NewScope())
804804
{
805+
if (switchStatementAst.Clauses.Count == 0)
806+
{
807+
return new[]
808+
{
809+
switchStatementAst.Default.Compile(this),
810+
Label(_loops.Break)
811+
};
812+
}
813+
805814
var clauses = new SwitchCase[switchStatementAst.Clauses.Count];
806815
for (var i = 0; i < clauses.Length; i++)
807816
{

0 commit comments

Comments
 (0)