[JS IR] Update an error on cross-module symbol redeclaration

The temporary solution for KT-50546.

The complete solution requires the understanding,
whether a cross-module symbol redeclaration is a valid case or not.
If the case is valid, the linker symbol table logic must be reworked.
This commit is contained in:
Alexander Korepanov
2021-12-28 14:42:03 +03:00
committed by Space
parent a153a1fefb
commit 4a29a8a7af
4 changed files with 40 additions and 1 deletions
@@ -99,8 +99,11 @@ private class JsIrModuleCrossModuleReferecenceBuilder(val module: JsIrModule, va
val tagToName = module.fragments.flatMap { it.nameBindings.entries }.associate { it.key to it.value }
val resultImports = imports.associate {
val tag = it.tag
require(it.module::exportNames.isInitialized) {
// This situation appears in case of a dependent module redefine a symbol (function) from their dependency
"Cross module dependency resolution failed due to symbol '${tag.takeWhile { c -> c != '|' }}' redefinition"
}
val exportedAs = it.module.exportNames[tag]!!
val importedAs = tagToName[tag]!!
val moduleName = it.module.module.import()
@@ -6922,6 +6922,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
runTest("js/js.translator/testData/box/multiModule/samePackageNames.kt");
}
@Test
@TestMetadata("symbolRedeclaration.kt")
public void testSymbolRedeclaration() throws Exception {
runTest("js/js.translator/testData/box/multiModule/symbolRedeclaration.kt");
}
@Test
@TestMetadata("useElementsFromDefaultPackageInAnotherModule.kt")
public void testUseElementsFromDefaultPackageInAnotherModule() throws Exception {
@@ -7306,6 +7306,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
runTest("js/js.translator/testData/box/multiModule/samePackageNames.kt");
}
@Test
@TestMetadata("symbolRedeclaration.kt")
public void testSymbolRedeclaration() throws Exception {
runTest("js/js.translator/testData/box/multiModule/symbolRedeclaration.kt");
}
@Test
@TestMetadata("useElementsFromDefaultPackageInAnotherModule.kt")
public void testUseElementsFromDefaultPackageInAnotherModule() throws Exception {
@@ -0,0 +1,24 @@
// IGNORE_BACKEND: JS_IR
// MODULE: AT
// FILE: at.kt
package foo
fun redeclaredFunction(): String = "OK"
// MODULE: A(AT)
// FILE: a.kt
package foo
fun userFunction(): String = redeclaredFunction()
// MODULE: main(A)
// FILE: main.kt
package foo
fun redeclaredFunction(): String = "Fail"
fun box(): String {
assertEquals(redeclaredFunction(), "Fail")
return userFunction()
}