diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 7c6192813e4..f9f03d6d6d5 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -1501,13 +1501,21 @@ class Fir2IrDeclarationStorage( ): IrSymbol { val fir = firSymbol.fir as F val irParent by lazy { findIrParent(fir) } - val signature by lazy { signatureComposer.composeSignature(fir, fakeOverrideOwnerLookupTag, forceTopLevelPrivate) } + val signature by lazy { + signatureComposer.composeSignature( + fir, + fakeOverrideOwnerLookupTag, + forceTopLevelPrivate = forceTopLevelPrivate, + forceExpect = fakeOverrideOwnerLookupTag?.toSymbol(session)?.isExpect == true + ) + } synchronized(symbolTable.lock) { getCachedIrDeclaration(fir, fakeOverrideOwnerLookupTag.takeIf { it !is ConeClassLookupTagWithFixedSymbol }) { // Parent calculation provokes declaration calculation for some members from IrBuiltIns @Suppress("UNUSED_EXPRESSION") irParent signature }?.let { return it.symbol } + val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED val declarationOrigin = computeDeclarationOrigin(firSymbol, parentOrigin) // TODO: package fragment members (?) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrSignatureComposer.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrSignatureComposer.kt index a013a9cbf5f..64c1d59bd94 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrSignatureComposer.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrSignatureComposer.kt @@ -18,6 +18,7 @@ interface Fir2IrSignatureComposer { declaration: FirDeclaration, containingClass: ConeClassLikeLookupTag? = null, forceTopLevelPrivate: Boolean = false, + forceExpect: Boolean = false, ): IdSignature? fun composeAccessorSignature( @@ -26,6 +27,7 @@ interface Fir2IrSignatureComposer { containingClass: ConeClassLikeLookupTag? = null, forceTopLevelPrivate: Boolean = false ): IdSignature? + fun composeTypeParameterSignature(typeParameter: FirTypeParameter, index: Int, containerSignature: IdSignature?): IdSignature? fun withFileSignature(sig: IdSignature.FileSignature, body: () -> Unit) } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/signaturer/FirBasedSignatureComposer.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/signaturer/FirBasedSignatureComposer.kt index a714c30077c..378487120be 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/signaturer/FirBasedSignatureComposer.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/signaturer/FirBasedSignatureComposer.kt @@ -32,16 +32,16 @@ class FirBasedSignatureComposer(override val mangler: FirMangler) : Fir2IrSignat fileSignature = null } - private data class FirDeclarationWithParentId(val declaration: FirDeclaration, val classId: ClassId?) + private data class FirDeclarationWithParentId(val declaration: FirDeclaration, val classId: ClassId?, val forceExpect: Boolean) private val signatureCache = mutableMapOf() - inner class SignatureBuilder : FirVisitor() { + inner class SignatureBuilder(private val forceExpect: Boolean) : FirVisitor() { var hashId: Long? = null var mask = 0L private fun setExpected(f: Boolean) { - mask = mask or IdSignature.Flags.IS_EXPECT.encode(f) + mask = mask or IdSignature.Flags.IS_EXPECT.encode(f || forceExpect) } override fun visitElement(element: FirElement, data: Any?) { @@ -89,6 +89,7 @@ class FirBasedSignatureComposer(override val mangler: FirMangler) : Fir2IrSignat declaration: FirDeclaration, containingClass: ConeClassLikeLookupTag?, forceTopLevelPrivate: Boolean, + forceExpect: Boolean, ): IdSignature? { if (declaration is FirAnonymousObject || declaration is FirAnonymousFunction) return null if (declaration is FirRegularClass && declaration.classId.isLocal) return null @@ -98,7 +99,7 @@ class FirBasedSignatureComposer(override val mangler: FirMangler) : Fir2IrSignat if (declaration.dispatchReceiverClassLookupTagOrNull()?.classId?.isLocal == true || containingClass?.classId?.isLocal == true) return null } - val declarationWithParentId = FirDeclarationWithParentId(declaration, containingClass?.classId) + val declarationWithParentId = FirDeclarationWithParentId(declaration, containingClass?.classId, forceExpect) val publicSignature = signatureCache.getOrPut(declarationWithParentId) { calculatePublicSignature(declarationWithParentId) } @@ -114,7 +115,7 @@ class FirBasedSignatureComposer(override val mangler: FirMangler) : Fir2IrSignat private fun calculatePublicSignature(declarationWithParentId: FirDeclarationWithParentId): IdSignature.CommonSignature { val (declaration, containingClassId) = declarationWithParentId - val builder = SignatureBuilder() + val builder = SignatureBuilder(declarationWithParentId.forceExpect) try { declaration.accept(builder, null) } catch (t: Throwable) { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index d02923298fd..c3a78d05973 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -33279,6 +33279,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @Test @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index 6b1716cae09..261a4bb5f75 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -33279,6 +33279,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @Test @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { diff --git a/compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt b/compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt new file mode 100644 index 00000000000..90cad03066b --- /dev/null +++ b/compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND_K1: ANY +// !LANGUAGE: +MultiPlatformProjects + +// MODULE: common +// FILE: common.kt + +expect class Runnable + +fun foo(arg: Runnable) { + arg.hashCode() +} + +// MODULE: main()()(common) +// FILE: test.kt + +actual class Runnable + +fun box() = "OK" diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 6f1472535de..19ec0fc66c2 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -31905,6 +31905,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @Test @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { 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 10dca014cfc..9d63dc787b4 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 @@ -33279,6 +33279,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @Test @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 3a90b204a59..76bf8a703f2 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -33279,6 +33279,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @Test @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 18c0b095d4f..28c008dbe82 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -27187,6 +27187,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { runTest("compiler/testData/codegen/box/multiplatform/k2/basic/correctParentForTypeParameter.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index f41fadecf2f..222fceeb5b8 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -23111,6 +23111,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); } + @Test + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @Test @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java index 2d9ccaa4c52..3b4be08bbb3 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java @@ -23225,6 +23225,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @Test @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index c9d8f729d81..b7efaa61f9d 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -23225,6 +23225,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @Test @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java index 5479fccf7ce..85087e765a4 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java @@ -23225,6 +23225,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); } + @Test + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @Test @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java index dde2d6a412f..9fe3e038f2b 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java @@ -26651,6 +26651,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); } + @Test + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @Test @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/K1NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/K1NativeCodegenBoxTestGenerated.java index c0c77809830..ff8cf528925 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/K1NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/K1NativeCodegenBoxTestGenerated.java @@ -26348,6 +26348,12 @@ public class K1NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); } + @Test + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @Test @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java index 493f976db84..58947524255 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java @@ -20705,6 +20705,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } + @TestMetadata("anyMethodInExpect.kt") + public void testAnyMethodInExpect() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/anyMethodInExpect.kt"); + } + @TestMetadata("correctParentForTypeParameter.kt") public void testCorrectParentForTypeParameter() throws Exception { runTest("compiler/testData/codegen/box/multiplatform/k2/basic/correctParentForTypeParameter.kt");