Skip to content

Commit 1278f29

Browse files
author
Troy Melhase
committed
Fixes empty statement (issue natural#3).
1 parent 2e9301f commit 1278f29

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

java2python/compiler/visitor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,11 @@ def acceptFor(self, node, memo):
426426
""" Accept and process a 'for' statement. """
427427
self.walk(node.firstChildOfType(tokens.FOR_INIT))
428428
whileStat = self.factory.statement('while', fs=FS.lsrc, parent=self)
429-
whileStat.expr.walk(node.firstChildOfType(tokens.FOR_CONDITION))
429+
cond = node.firstChildOfType(tokens.FOR_CONDITION)
430+
if not cond.children:
431+
whileStat.expr.right = 'True'
432+
else:
433+
whileStat.expr.walk(cond)
430434
whileBlock = self.factory.methodContent(parent=self)
431435
whileBlock.walk(node.firstChildOfType(tokens.BLOCK_SCOPE))
432436
updateStat = self.factory.expr(parent=whileBlock)

test/ForLoop1.java

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

0 commit comments

Comments
 (0)