Skip to content

Commit fa8a410

Browse files
author
Troy Melhase
committed
Support for if/else if/else with empty final else. Fixes natural#16.
1 parent 9590d48 commit fa8a410

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

java2python/compiler/visitor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,11 @@ def acceptIf(self, node, memo):
495495
elseBlock = self.factory.expr(parent=elseStat)
496496
elseBlock.walk(nextNode, memo)
497497
elif nextType: # nextType != tokens.BLOCK_SCOPE:
498-
self.factory.statement('else', fs=FS.lc, parent=self)
499-
self.factory.methodContent(parent=self).walk(nextNode, memo)
498+
elseStat = self.factory.statement('else', fs=FS.lc, parent=self)
499+
if nextNode.children:
500+
self.factory.methodContent(parent=self).walk(nextNode, memo)
501+
else:
502+
self.factory.expr(left='pass', parent=elseStat)
500503

501504

502505
def acceptSwitch(self, node, memo):

test/If7.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class If7 {
2+
public static void main(String[] args) {
3+
if (false) {
4+
System.out.println("fail 1");
5+
} else if (false) {
6+
System.out.println("fail 2");
7+
} else {
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)