fix: function inlining without blocks for else statement.

This commit is contained in:
Artem Kobzar
2022-04-20 09:28:45 +00:00
committed by Space
parent 207f2c7981
commit 333440dfc6
4 changed files with 40 additions and 1 deletions
@@ -746,7 +746,7 @@ public class JsToStringGenerationVisitor extends JsVisitor {
space();
}
sourceLocationConsumer.pushSourceInfo(null);
accept(elseStatement);
accept(materialize(elseStatement));
sourceLocationConsumer.popSourceInfo();
if (!elseIf) {
nestedPop(elseStatement);
@@ -4574,6 +4574,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
runTest("js/js.translator/testData/box/inline/astCopy.kt");
}
@Test
@TestMetadata("blocksMaterialization.kt")
public void testBlocksMaterialization() throws Exception {
runTest("js/js.translator/testData/box/inline/blocksMaterialization.kt");
}
@Test
@TestMetadata("callFunction.kt")
public void testCallFunction() throws Exception {
@@ -4952,6 +4952,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
runTest("js/js.translator/testData/box/inline/astCopy.kt");
}
@Test
@TestMetadata("blocksMaterialization.kt")
public void testBlocksMaterialization() throws Exception {
runTest("js/js.translator/testData/box/inline/blocksMaterialization.kt");
}
@Test
@TestMetadata("callFunction.kt")
public void testCallFunction() throws Exception {
@@ -0,0 +1,27 @@
// EXPECTED_REACHABLE_NODES: 1282
package foo
inline fun dangerCall() {
assertEquals("A", "A")
assertNotEquals("A", "A")
}
fun box(): String {
if ("A" != "A") dangerCall()
if ("A" == "A") {
// Nothing to do
} else dangerCall()
while ("A" != "A") dangerCall()
for (num in 0 until 0) dangerCall()
when ("A") {
"A" -> {}
else -> dangerCall()
}
return "OK"
}