[JS IR] Not cast to declaration parent in JsCodeOutlineLowering, use parent otherwise
^KT-45057 fixed
This commit is contained in:
+6
-1
@@ -30,12 +30,14 @@ import org.jetbrains.kotlin.ir.expressions.IrContainerExpression
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.util.constructors
|
import org.jetbrains.kotlin.ir.util.constructors
|
||||||
|
import org.jetbrains.kotlin.ir.util.dumpKotlinLike
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||||
import org.jetbrains.kotlin.js.backend.ast.*
|
import org.jetbrains.kotlin.js.backend.ast.*
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
|
import java.lang.IllegalStateException
|
||||||
|
|
||||||
// Outlines `kotlin.js.js(code: String)` calls where JS code references Kotlin locals.
|
// Outlines `kotlin.js.js(code: String)` calls where JS code references Kotlin locals.
|
||||||
// Makes locals usages explicit.
|
// Makes locals usages explicit.
|
||||||
@@ -164,7 +166,10 @@ private class JsCodeOutlineTransformer(
|
|||||||
}
|
}
|
||||||
// We don't need this function's body. Using empty block body stub, because some code might expect all functions to have bodies.
|
// We don't need this function's body. Using empty block body stub, because some code might expect all functions to have bodies.
|
||||||
outlinedFunction.body = backendContext.irFactory.createBlockBody(UNDEFINED_OFFSET, UNDEFINED_OFFSET)
|
outlinedFunction.body = backendContext.irFactory.createBlockBody(UNDEFINED_OFFSET, UNDEFINED_OFFSET)
|
||||||
outlinedFunction.parent = container as IrDeclarationParent
|
outlinedFunction.parent = when (container) {
|
||||||
|
is IrDeclarationParent -> container
|
||||||
|
else -> container.parent
|
||||||
|
}
|
||||||
kotlinLocalsUsedInJs.forEach { local ->
|
kotlinLocalsUsedInJs.forEach { local ->
|
||||||
outlinedFunction.addValueParameter {
|
outlinedFunction.addValueParameter {
|
||||||
name = local.name
|
name = local.name
|
||||||
|
|||||||
Generated
+5
@@ -5105,6 +5105,11 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
|||||||
runTest("js/js.translator/testData/box/jsCode/if.kt");
|
runTest("js/js.translator/testData/box/jsCode/if.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("init.kt")
|
||||||
|
public void testInit() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/jsCode/init.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("invocation.kt")
|
@TestMetadata("invocation.kt")
|
||||||
public void testInvocation() throws Exception {
|
public void testInvocation() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/jsCode/invocation.kt");
|
runTest("js/js.translator/testData/box/jsCode/invocation.kt");
|
||||||
|
|||||||
+5
@@ -5105,6 +5105,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/jsCode/if.kt");
|
runTest("js/js.translator/testData/box/jsCode/if.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("init.kt")
|
||||||
|
public void testInit() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/jsCode/init.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("invocation.kt")
|
@TestMetadata("invocation.kt")
|
||||||
public void testInvocation() throws Exception {
|
public void testInvocation() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/jsCode/invocation.kt");
|
runTest("js/js.translator/testData/box/jsCode/invocation.kt");
|
||||||
|
|||||||
+5
@@ -5120,6 +5120,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/jsCode/if.kt");
|
runTest("js/js.translator/testData/box/jsCode/if.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("init.kt")
|
||||||
|
public void testInit() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/jsCode/init.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("invocation.kt")
|
@TestMetadata("invocation.kt")
|
||||||
public void testInvocation() throws Exception {
|
public void testInvocation() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/jsCode/invocation.kt");
|
runTest("js/js.translator/testData/box/jsCode/invocation.kt");
|
||||||
|
|||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
// EXPECTED_REACHABLE_NODES: 1282
|
||||||
|
package foo
|
||||||
|
|
||||||
|
class A {
|
||||||
|
var ok: String
|
||||||
|
|
||||||
|
init {
|
||||||
|
var ok = "fail"
|
||||||
|
ok = js(
|
||||||
|
"""
|
||||||
|
ok = 'OK'
|
||||||
|
return ok
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
this.ok = ok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return A().ok
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user