KJS: Fix loop levels in ContinueReplacingVisitor (KT-24777)
This commit is contained in:
+3
-3
@@ -29,9 +29,9 @@ object LabeledBlockToDoWhileTransformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun JsStatement.isLoop(): Boolean = when (this) {
|
fun JsStatement.isLoop(): Boolean = when (this) {
|
||||||
is JsWhile -> true
|
is JsWhile,
|
||||||
is JsDoWhile -> true
|
is JsDoWhile,
|
||||||
is JsFor -> true
|
is JsFor,
|
||||||
is JsForIn -> true
|
is JsForIn -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -26,6 +26,7 @@ class ContinueReplacingVisitor(val loopLabelName: JsName?, val guardLabelName: J
|
|||||||
override fun visit(x: JsContinue, ctx: JsContext<JsNode>): Boolean {
|
override fun visit(x: JsContinue, ctx: JsContext<JsNode>): Boolean {
|
||||||
val target = x.label?.name
|
val target = x.label?.name
|
||||||
val shouldReplace = if (target == null) loopNestingLevel == 0 else target == loopLabelName
|
val shouldReplace = if (target == null) loopNestingLevel == 0 else target == loopLabelName
|
||||||
|
assert(loopNestingLevel >= 0)
|
||||||
if (shouldReplace) {
|
if (shouldReplace) {
|
||||||
ctx.replaceMe(JsBreak(guardLabelName.makeRef()))
|
ctx.replaceMe(JsBreak(guardLabelName.makeRef()))
|
||||||
}
|
}
|
||||||
@@ -42,6 +43,7 @@ class ContinueReplacingVisitor(val loopLabelName: JsName?, val guardLabelName: J
|
|||||||
|
|
||||||
override fun endVisit(x: JsWhile, ctx: JsContext<JsNode>) {
|
override fun endVisit(x: JsWhile, ctx: JsContext<JsNode>) {
|
||||||
super.endVisit(x, ctx)
|
super.endVisit(x, ctx)
|
||||||
|
if (loopLabelName == null) return
|
||||||
loopNestingLevel--
|
loopNestingLevel--
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +56,7 @@ class ContinueReplacingVisitor(val loopLabelName: JsName?, val guardLabelName: J
|
|||||||
|
|
||||||
override fun endVisit(x: JsDoWhile, ctx: JsContext<JsNode>) {
|
override fun endVisit(x: JsDoWhile, ctx: JsContext<JsNode>) {
|
||||||
super.endVisit(x, ctx)
|
super.endVisit(x, ctx)
|
||||||
|
if (loopLabelName == null) return
|
||||||
loopNestingLevel--
|
loopNestingLevel--
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,6 +69,7 @@ class ContinueReplacingVisitor(val loopLabelName: JsName?, val guardLabelName: J
|
|||||||
|
|
||||||
override fun endVisit(x: JsFor, ctx: JsContext<JsNode>) {
|
override fun endVisit(x: JsFor, ctx: JsContext<JsNode>) {
|
||||||
super.endVisit(x, ctx)
|
super.endVisit(x, ctx)
|
||||||
|
if (loopLabelName == null) return
|
||||||
loopNestingLevel--
|
loopNestingLevel--
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +82,7 @@ class ContinueReplacingVisitor(val loopLabelName: JsName?, val guardLabelName: J
|
|||||||
|
|
||||||
override fun endVisit(x: JsForIn, ctx: JsContext<JsNode>) {
|
override fun endVisit(x: JsForIn, ctx: JsContext<JsNode>) {
|
||||||
super.endVisit(x, ctx)
|
super.endVisit(x, ctx)
|
||||||
|
if (loopLabelName == null) return
|
||||||
loopNestingLevel--
|
loopNestingLevel--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -3724,6 +3724,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/inline/classObject.kt");
|
runTest("js/js.translator/testData/box/inline/classObject.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("continueInLoopWithInlinableCondition.kt")
|
||||||
|
public void testContinueInLoopWithInlinableCondition() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/inline/continueInLoopWithInlinableCondition.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("dontInlineFunctionCall.kt")
|
@TestMetadata("dontInlineFunctionCall.kt")
|
||||||
public void testDontInlineFunctionCall() throws Exception {
|
public void testDontInlineFunctionCall() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/inline/dontInlineFunctionCall.kt");
|
runTest("js/js.translator/testData/box/inline/dontInlineFunctionCall.kt");
|
||||||
|
|||||||
+5
@@ -3724,6 +3724,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/inline/classObject.kt");
|
runTest("js/js.translator/testData/box/inline/classObject.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("continueInLoopWithInlinableCondition.kt")
|
||||||
|
public void testContinueInLoopWithInlinableCondition() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/inline/continueInLoopWithInlinableCondition.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("dontInlineFunctionCall.kt")
|
@TestMetadata("dontInlineFunctionCall.kt")
|
||||||
public void testDontInlineFunctionCall() throws Exception {
|
public void testDontInlineFunctionCall() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/inline/dontInlineFunctionCall.kt");
|
runTest("js/js.translator/testData/box/inline/dontInlineFunctionCall.kt");
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// EXPECTED_REACHABLE_NODES: 1122
|
||||||
|
/*
|
||||||
|
Modified test case from KT-24777
|
||||||
|
*/
|
||||||
|
package foo
|
||||||
|
|
||||||
|
inline fun condition() = false
|
||||||
|
|
||||||
|
fun run(x: Boolean): String {
|
||||||
|
var y = 0
|
||||||
|
do {
|
||||||
|
if (y > 0)
|
||||||
|
return "NOT OK"
|
||||||
|
y += 1
|
||||||
|
do {
|
||||||
|
} while (false)
|
||||||
|
if (x) continue
|
||||||
|
} while (condition())
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return run(true)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user