Skip to content

Commit

Permalink
[Truffle] Fixed an issue with nesting while statements and breaks.
Browse files Browse the repository at this point in the history
Our translator keeps track of break statements inside of whiles via the 'translatingWhile' boolean flag.  Prior to this change, whenever we finished visiting a while node we'd reset the boolean to false.  This presented a problem for code with nested while loops and a break statement in the outer while, but outside and after the body of the inner while.  The inner while would reset the value and when we visited the break node we'd erroneously think it was outside the body of any while node.  By restoring the flag value when we exit, we can keep track through arbitrarily nested whiles.  This assumes the default value is 'false', which it is.
nirvdrum committed Feb 9, 2015
1 parent 944a8b7 commit d3a69a4
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -2527,14 +2527,15 @@ public RubyNode visitWhileNode(org.jruby.ast.WhileNode node) {

RubyNode condition = node.getConditionNode().accept(this);

final boolean oldTranslatingWhile = translatingWhile;
translatingWhile = true;

final RubyNode body;

try {
body = node.getBodyNode().accept(this);
} finally {
translatingWhile = false;
translatingWhile = oldTranslatingWhile;
}

if (node.evaluateAtStart()) {

0 comments on commit d3a69a4

Please sign in to comment.