diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java index 9d462b10330..eb24ebb5e3f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java @@ -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) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java index d425d59f21e..2841aff46bb 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachArray.java @@ -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); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java index ce4507ed983..57acb07aa6a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSubEachIterable.java @@ -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); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicStatementTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicStatementTests.java index a4f85f393bf..fdfa912fbf8 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicStatementTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicStatementTests.java @@ -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;" + )); + } }