Fix break bug in for/foreach loops.
This commit is contained in:
parent
9bedbbaa6a
commit
c60885b5d4
|
@ -183,6 +183,8 @@ public final class SFor extends AStatement {
|
|||
writer.writeLoopCounter(loopCounter.getSlot(), statementCount, location);
|
||||
}
|
||||
|
||||
block.continu = begin;
|
||||
block.brake = end;
|
||||
block.write(writer, globals);
|
||||
} else {
|
||||
if (loopCounter != null) {
|
||||
|
|
|
@ -100,6 +100,8 @@ final class SSubEachArray extends AStatement {
|
|||
writer.writeLoopCounter(loopCounter.getSlot(), statementCount, location);
|
||||
}
|
||||
|
||||
block.continu = begin;
|
||||
block.brake = end;
|
||||
block.write(writer, globals);
|
||||
|
||||
writer.goTo(begin);
|
||||
|
|
|
@ -122,6 +122,8 @@ final class SSubEachIterable extends AStatement {
|
|||
writer.writeLoopCounter(loopCounter.getSlot(), statementCount, location);
|
||||
}
|
||||
|
||||
block.continu = begin;
|
||||
block.brake = end;
|
||||
block.write(writer, globals);
|
||||
|
||||
writer.goTo(begin);
|
||||
|
|
|
@ -272,4 +272,34 @@ public class BasicStatementTests extends ScriptTestCase {
|
|||
null, true
|
||||
));
|
||||
}
|
||||
|
||||
public void testForWithBreak() {
|
||||
assertEquals(1, exec(
|
||||
"Map settings = ['test1' : '1'];" +
|
||||
"int setting = 0;" +
|
||||
"List keys = ['test0', 'test1', 'test2'];" +
|
||||
"for (int i = 0; i < keys.size(); ++i) {" +
|
||||
" if (settings.containsKey(keys[i])) {" +
|
||||
" setting = Integer.parseInt(settings[keys[i]]);" +
|
||||
" break;" +
|
||||
" }" +
|
||||
"}" +
|
||||
"return setting;"
|
||||
));
|
||||
}
|
||||
|
||||
public void testForEachWithBreak() {
|
||||
assertEquals(1, exec(
|
||||
"Map settings = ['test1' : '1'];" +
|
||||
"int setting = 0;" +
|
||||
"List keys = ['test0', 'test1', 'test2'];" +
|
||||
"for (String key : keys) {" +
|
||||
" if (settings.containsKey(key)) {" +
|
||||
" setting = Integer.parseInt(settings[key]);" +
|
||||
" break;" +
|
||||
" }" +
|
||||
"}" +
|
||||
"return setting;"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue