Skip to content

Commit 18d6a9f

Browse files
committed
Fixed handling of empty keys in emitSWITCH.
The problem of emitSWITCH not handling empty keys popped up when I tried to implement unfolding of pattern alternatives in genicode instead of in typers/explicitouter. This change makes perfect sense in isolation as bytecode allows LOOKUPSWITCHes that have only default case. I actually verified that this kind of bytecode is generated by javac when one has switch statement with only default case defined. Review by @paulp or @dragos.
1 parent 37bcff7 commit 18d6a9f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/fjbg.jar.desired.sha1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9aa9c99b8032e454f1f85d27de31a88b3dec1045 ?fjbg.jar
1+
c3f9b576c91cb9761932ad936ccc4a71f33d2ef2 ?fjbg.jar

src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,16 @@ public void emitSWITCH(int[] keys,
596596
double minDensity) {
597597
assert keys.length == branches.length;
598598

599+
//The special case for empty keys. It makes sense to allow
600+
//empty keys and generate LOOKUPSWITCH with defaultBranch
601+
//only. This is exactly what javac does for switch statement
602+
//that has only a default case.
603+
if (keys.length == 0) {
604+
emitLOOKUPSWITCH(keys, branches, defaultBranch);
605+
return;
606+
}
607+
//the rest of the code assumes that keys.length > 0
608+
599609
// sorting the tables
600610
// FIXME use quicksort
601611
for (int i = 1; i < keys.length; i++) {

0 commit comments

Comments
 (0)