[JS IC] fix cross-module nested class references and interface inheritance
^ KT-50528 fixed
This commit is contained in:
@@ -99,7 +99,7 @@ fun compileWithIC(
|
|||||||
module.files.filter { it.fileEntry.name in dirties }
|
module.files.filter { it.fileEntry.name in dirties }
|
||||||
} ?: module.files
|
} ?: module.files
|
||||||
|
|
||||||
val ast = transformer.generateBinaryAst(dirtyFiles)
|
val ast = transformer.generateBinaryAst(dirtyFiles, allModules)
|
||||||
|
|
||||||
ast.entries.forEach { (path, bytes) -> cacheConsumer.commitBinaryAst(path, bytes) }
|
ast.entries.forEach { (path, bytes) -> cacheConsumer.commitBinaryAst(path, bytes) }
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -104,14 +104,18 @@ class IrModuleToJsTransformerTmp(
|
|||||||
return CompilerResult(result, dts)
|
return CompilerResult(result, dts)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateBinaryAst(files: Iterable<IrFile>): Map<String, ByteArray> {
|
fun generateBinaryAst(files: Iterable<IrFile>, allModules: Iterable<IrModuleFragment>): Map<String, ByteArray> {
|
||||||
val exportModelGenerator = ExportModelGenerator(backendContext, generateNamespacesForPackages = true)
|
val exportModelGenerator = ExportModelGenerator(backendContext, generateNamespacesForPackages = true)
|
||||||
|
|
||||||
val exportData = files.associate { file ->
|
val exportData = files.associate { file ->
|
||||||
file to exportModelGenerator.generateExportWithExternals(file)
|
file to exportModelGenerator.generateExportWithExternals(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
files.forEach { StaticMembersLowering(backendContext).lower(it) }
|
allModules.forEach {
|
||||||
|
it.files.forEach {
|
||||||
|
StaticMembersLowering(backendContext).lower(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val serializer = JsIrAstSerializer()
|
val serializer = JsIrAstSerializer()
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -301,7 +301,7 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
|
|||||||
?.let {
|
?.let {
|
||||||
val implClassDeclaration = it.parent as IrClass
|
val implClassDeclaration = it.parent as IrClass
|
||||||
|
|
||||||
if (implClassDeclaration.shouldCopyFrom() && it.body != null) {
|
if (implClassDeclaration.shouldCopyFrom()) {
|
||||||
val reference = context.getNameForStaticDeclaration(it).makeRef()
|
val reference = context.getNameForStaticDeclaration(it).makeRef()
|
||||||
classModel.postDeclarationBlock.statements += jsAssignment(memberRef, reference).makeStmt()
|
classModel.postDeclarationBlock.statements += jsAssignment(memberRef, reference).makeStmt()
|
||||||
if (isFakeOverride) {
|
if (isFakeOverride) {
|
||||||
|
|||||||
@@ -4210,6 +4210,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/incremental/inlineSuspendFun.kt");
|
runTest("js/js.translator/testData/box/incremental/inlineSuspendFun.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("interfaceInheritanceCrossModule.kt")
|
||||||
|
public void testInterfaceInheritanceCrossModule() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/incremental/interfaceInheritanceCrossModule.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("jsModule.kt")
|
@TestMetadata("jsModule.kt")
|
||||||
public void testJsModule() throws Exception {
|
public void testJsModule() throws Exception {
|
||||||
@@ -4228,6 +4234,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/incremental/multipleReimport.kt");
|
runTest("js/js.translator/testData/box/incremental/multipleReimport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("nestedClassesInDependency.kt")
|
||||||
|
public void testNestedClassesInDependency() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/incremental/nestedClassesInDependency.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("packagesWithSameName.kt")
|
@TestMetadata("packagesWithSameName.kt")
|
||||||
public void testPackagesWithSameName() throws Exception {
|
public void testPackagesWithSameName() throws Exception {
|
||||||
|
|||||||
+12
@@ -4582,6 +4582,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/incremental/inlineSuspendFun.kt");
|
runTest("js/js.translator/testData/box/incremental/inlineSuspendFun.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("interfaceInheritanceCrossModule.kt")
|
||||||
|
public void testInterfaceInheritanceCrossModule() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/incremental/interfaceInheritanceCrossModule.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("jsModule.kt")
|
@TestMetadata("jsModule.kt")
|
||||||
public void testJsModule() throws Exception {
|
public void testJsModule() throws Exception {
|
||||||
@@ -4600,6 +4606,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/incremental/multipleReimport.kt");
|
runTest("js/js.translator/testData/box/incremental/multipleReimport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("nestedClassesInDependency.kt")
|
||||||
|
public void testNestedClassesInDependency() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/incremental/nestedClassesInDependency.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("packagesWithSameName.kt")
|
@TestMetadata("packagesWithSameName.kt")
|
||||||
public void testPackagesWithSameName() throws Exception {
|
public void testPackagesWithSameName() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// NO_COMMON_FILES
|
||||||
|
// MODULE: lib
|
||||||
|
// FILE: lib.kt
|
||||||
|
|
||||||
|
package lib
|
||||||
|
|
||||||
|
interface A {
|
||||||
|
fun foo() = 23
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODULE: main(lib)
|
||||||
|
// FILE: main.kt
|
||||||
|
// RECOMPILE
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import lib.A
|
||||||
|
|
||||||
|
class B : A {
|
||||||
|
fun bar() = foo() + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val result = B().bar()
|
||||||
|
if (result != 24) return "fail: $result"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// NO_COMMON_FILES
|
||||||
|
// MODULE: lib
|
||||||
|
// FILE: lib.kt
|
||||||
|
|
||||||
|
class A {
|
||||||
|
class B(val msg: String)
|
||||||
|
|
||||||
|
fun foo(b: B) = b.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODULE: main(lib)
|
||||||
|
// FILE: main.kt
|
||||||
|
// RECOMPILE
|
||||||
|
|
||||||
|
fun box() = A().foo(A.B("OK"))
|
||||||
Reference in New Issue
Block a user