JS: fix compiler crash when optimizing JS AST with empty do..while statement. See KT-15513

This commit is contained in:
Alexey Andreev
2017-01-10 12:35:04 +03:00
parent bad6f41d6e
commit ee74342fbe
6 changed files with 14 additions and 11 deletions
@@ -1,6 +1,3 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
fun box(): String { fun box(): String {
OUTER@while (true) { OUTER@while (true) {
var x = "" var x = ""
@@ -62,7 +62,7 @@ internal class DoWhileGuardElimination(private val root: JsStatement) {
val body = x.body val body = x.body
val guard = when (body) { val guard = when (body) {
is JsBlock -> { is JsBlock -> {
val firstStatement = body.statements.first() val firstStatement = body.statements.firstOrNull()
if (firstStatement is JsLabel && body.statements.size == 1) { if (firstStatement is JsLabel && body.statements.size == 1) {
firstStatement firstStatement
} }
@@ -24,4 +24,6 @@ class DoWhileGuardEliminationTest : BasicOptimizerTest("do-while-guard-eliminati
@Test fun innerContinue() = box() @Test fun innerContinue() = box()
@Test fun innerBreakInLoopWithoutLabel() = box() @Test fun innerBreakInLoopWithoutLabel() = box()
@Test fun emptyDoWhile() = box()
} }
@@ -5033,13 +5033,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
@TestMetadata("breakFromOuter.kt") @TestMetadata("breakFromOuter.kt")
public void testBreakFromOuter() throws Exception { public void testBreakFromOuter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/breakFromOuter.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/breakFromOuter.kt");
try { doTest(fileName);
doTest(fileName);
}
catch (Throwable ignore) {
return;
}
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
} }
@TestMetadata("breakInDoWhile.kt") @TestMetadata("breakInDoWhile.kt")
@@ -0,0 +1,5 @@
function box() {
do {
} while (false);
return "OK"
}
@@ -0,0 +1,5 @@
function box() {
do {
} while (false);
return "OK"
}