diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 725b714d9ff..08d1384f5ed 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -33142,6 +33142,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/multiplatform/multiModule/getRidOfDoubleBindingInFir2IrLazyProperty.kt"); } + @Test + @TestMetadata("hmppSimple.kt") + public void testHmppSimple() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/multiModule/hmppSimple.kt"); + } + @Test @TestMetadata("independentCommonSourceModules.kt") public void testIndependentCommonSourceModules() throws Exception { diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/ExpectActualCollector.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/ExpectActualCollector.kt index fc3c578d919..f8c1d95b2a8 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/ExpectActualCollector.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/ExpectActualCollector.kt @@ -33,7 +33,10 @@ internal class ExpectActualCollector(private val mainFragment: IrModuleFragment, val allActualDeclarations = mutableSetOf() val typeAliasMap = mutableMapOf() // It's used to link members from expect class that have typealias actual - ActualClassifiersCollector(actualClassifiers, allActualDeclarations, typeAliasMap).visitModuleFragment(mainFragment, false) + val fragmentsWithActuals = (dependentFragments.drop(1) + mainFragment) + for (fragment in fragmentsWithActuals) { + ActualClassifiersCollector(actualClassifiers, allActualDeclarations, typeAliasMap).visitModuleFragment(fragment, false) + } val linkCollector = ClassifiersLinkCollector(this, actualClassifiers) dependentFragments.forEach { linkCollector.visitModuleFragment(it) } @@ -187,4 +190,4 @@ internal class ExpectActualCollector(private val mainFragment: IrModuleFragment, element.acceptChildrenVoid(this) } } -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/multiplatform/multiModule/hmppSimple.kt b/compiler/testData/codegen/box/multiplatform/multiModule/hmppSimple.kt new file mode 100644 index 00000000000..a447a73e340 --- /dev/null +++ b/compiler/testData/codegen/box/multiplatform/multiModule/hmppSimple.kt @@ -0,0 +1,69 @@ +// TARGET_BACKEND: JVM_IR +// !LANGUAGE: +MultiPlatformProjects + +// MODULE: common +// TARGET_PLATFORM: Common +// FILE: common.kt + +expect class A constructor() { + fun foo(): String +} + +expect class B constructor() { + fun bar(): String +} + +expect fun func(): String + +expect var prop: String + +fun test_1(): String { + val a = A() + val b = B() + prop = "Set prop in common." + return "${func()} $prop ${a.foo()} ${b.bar()}" +} + +// MODULE: intermediate()()(common) +// TARGET_PLATFORM: Common +// FILE: intermediate.kt + +actual fun func(): String = "Actual func." + +actual class B actual constructor() { + actual fun bar(): String = "Actual B." +} + +expect class C constructor() { + fun baz(): String +} + +fun test_2(): String { + val a = A() + val b = B() + val c = C() + prop = "Set prop in intermediate." + return "${func()} $prop ${a.foo()} ${b.bar()} ${c.baz()}" +} + +// MODULE: jvm()()(intermediate) +// TARGET_PLATFORM: JVM +// FILE: main.kt + +actual var prop: String = "!" + +actual class A actual constructor() { + actual fun foo(): String = "Actual A." +} + +actual class C actual constructor() { + actual fun baz(): String = "Actual C." +} + +fun box(): String { + val s1 = test_1() + if (s1 != "Actual func. Set prop in common. Actual A. Actual B.") return s1 + val s2 = test_2() + if (s2 != "Actual func. Set prop in intermediate. Actual A. Actual B. Actual C.") return s2 + return "OK" +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 150aaba89b1..670aff539ce 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -33142,6 +33142,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/multiplatform/multiModule/getRidOfDoubleBindingInFir2IrLazyProperty.kt"); } + @Test + @TestMetadata("hmppSimple.kt") + public void testHmppSimple() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/multiModule/hmppSimple.kt"); + } + @Test @TestMetadata("independentCommonSourceModules.kt") public void testIndependentCommonSourceModules() throws Exception {