chore: remove unused break statements from inlined functions bodies.
This commit is contained in:
+6
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.backend.js.transformers.irToJs
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.compilationException
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.isTheLastReturnStatementIn
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.JsGenerationContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.emptyScope
|
||||
@@ -94,7 +94,11 @@ class IrElementToJsStatementTransformer : BaseIrElementToJsNodeTransformer<JsSta
|
||||
val lastStatementTransformer: (JsExpression) -> JsStatement =
|
||||
if (targetSymbol is IrReturnableBlockSymbol) {
|
||||
// TODO assert that value is Unit?
|
||||
{ JsBreak(context.getNameForReturnableBlock(targetSymbol.owner)!!.makeRef()) }
|
||||
{
|
||||
context.getNameForReturnableBlock(targetSymbol.owner)
|
||||
.takeIf { !expression.isTheLastReturnStatementIn(targetSymbol) }
|
||||
?.run { JsBreak(makeRef()) } ?: JsEmpty
|
||||
}
|
||||
} else {
|
||||
{ JsReturn(it) }
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.descriptors.isInterface
|
||||
import org.jetbrains.kotlin.descriptors.isClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.expressions.IrReturn
|
||||
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
||||
import org.jetbrains.kotlin.ir.util.parentClassOrNull
|
||||
|
||||
fun IrDeclaration.isExportedMember() =
|
||||
@@ -21,4 +23,8 @@ fun IrDeclaration?.isExportedInterface() =
|
||||
this is IrClass && kind.isInterface && isJsExport()
|
||||
|
||||
fun IrDeclaration.isExportedInterfaceMember() =
|
||||
parentClassOrNull.isExportedInterface()
|
||||
parentClassOrNull.isExportedInterface()
|
||||
|
||||
fun IrReturn.isTheLastReturnStatementIn(target: IrReturnableBlockSymbol): Boolean {
|
||||
return target.owner.statements.lastOrNull() === this
|
||||
}
|
||||
@@ -339,7 +339,7 @@ class LocalNameGenerator(val variableNames: NameTable<IrDeclaration>) : IrElemen
|
||||
|
||||
override fun visitReturn(expression: IrReturn) {
|
||||
val targetSymbol = expression.returnTargetSymbol
|
||||
if (targetSymbol is IrReturnableBlockSymbol) {
|
||||
if (targetSymbol is IrReturnableBlockSymbol && !expression.isTheLastReturnStatementIn(targetSymbol)) {
|
||||
persistReturnableBlockName(SYNTHETIC_BLOCK_LABEL, targetSymbol.owner)
|
||||
}
|
||||
|
||||
|
||||
@@ -4844,6 +4844,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/inline/lambdaReassignmentWithCapture.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lastLabeledReturn.kt")
|
||||
public void testLastLabeledReturn() throws Exception {
|
||||
runTest("js/js.translator/testData/box/inline/lastLabeledReturn.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localDeclarationsClash.kt")
|
||||
public void testLocalDeclarationsClash() throws Exception {
|
||||
|
||||
+6
@@ -5222,6 +5222,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/inline/lambdaReassignmentWithCapture.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lastLabeledReturn.kt")
|
||||
public void testLastLabeledReturn() throws Exception {
|
||||
runTest("js/js.translator/testData/box/inline/lastLabeledReturn.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localDeclarationsClash.kt")
|
||||
public void testLocalDeclarationsClash() throws Exception {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
inline fun foo(l: () -> Unit) { l() }
|
||||
inline fun bar(l: () -> Unit) { l() }
|
||||
|
||||
fun box(): String {
|
||||
foo {
|
||||
bar {
|
||||
return@foo;
|
||||
}
|
||||
return "Failed: labeled return was not added"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user