Skip to content

Commit c9d3f59

Browse files
committed
Fix switch statements not adding SSA successors
1 parent 40b505d commit c9d3f59

5 files changed

Lines changed: 55 additions & 2 deletions

File tree

Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementSwitch.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ public CompilingStatement compile(StatementCompiler compiler, CodeBlock lastBloc
4141
Compiling result = new Compiling(compiler, value, tail);
4242
StatementCompiler innerScope = compiler.forLoop(result);
4343

44-
CodeBlock next = new CodeBlock();
44+
CodeBlock next = lastBlock.createNext();
4545
for (ParsedSwitchCase switchCase : cases) {
4646
CodeBlock current = next;
47-
next = new CodeBlock();
47+
current.addSuccessor(tail);
48+
next = lastBlock.createNext();
4849
result.continueBlock = next;
4950
result.cases.add(switchCase.compile(innerScope, current));
5051
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#output: Hello World
2+
3+
val field = "Hello World";
4+
5+
switch field {
6+
case "Hello World":
7+
println("Hello World");
8+
break;
9+
case "Goodbye World":
10+
println("this is bad");
11+
break;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#output: Hello World
2+
3+
val field = "Hello World";
4+
5+
switch(field) {
6+
case "Hello World":
7+
println("Hello World");
8+
break;
9+
case "Goodbye World":
10+
println("this is bad");
11+
break;
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#output: Hello World
2+
3+
val field = "Hello World";
4+
5+
if true {
6+
switch field {
7+
case "Hello World":
8+
println("Hello World");
9+
break;
10+
case "Goodbye World":
11+
println("this is bad");
12+
break;
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#output: Hello World
2+
3+
val field = "Hello World";
4+
5+
if false {} else {
6+
switch field {
7+
case "Hello World":
8+
println("Hello World");
9+
break;
10+
case "Goodbye World":
11+
println("this is bad");
12+
break;
13+
}
14+
}

0 commit comments

Comments
 (0)