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 d2724e1af13..6636dec68ce 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 @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.declarations.utils.visibility import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.visitors.FirVisitor import org.jetbrains.kotlin.ir.util.IdSignature +import org.jetbrains.kotlin.name.FqName // @NoMutableState -- we'll restore this annotation once we get rid of withFileSignature(). class FirBasedSignatureComposer(override val mangler: FirMangler) : Fir2IrSignatureComposer { @@ -122,7 +123,7 @@ class FirBasedSignatureComposer(override val mangler: FirMangler) : Fir2IrSignat else -> error("Unsupported FIR declaration in signature composer: ${declaration.render()}") } return if (isTopLevelPrivate(declaration) || forceTopLevelPrivate) { - val fileSig = fileSignature ?: return null + val fileSig = fileSignature ?: declaration.fakeFileSignature(publicSignature) IdSignature.CompositeSignature(fileSig, publicSignature) } else publicSignature @@ -181,6 +182,13 @@ class FirBasedSignatureComposer(override val mangler: FirMangler) : Fir2IrSignat private fun isTopLevelPrivate(declaration: FirDeclaration): Boolean = declaration.symbol.getOwnerLookupTag() == null && declaration is FirMemberDeclaration && declaration.visibility == Visibilities.Private + // We only need file signatures to distinguish between declarations with the same fqName across different files, + // so FirDeclaration itself is an appropriate id. + private fun FirDeclaration.fakeFileSignature(commonSignature: IdSignature.CommonSignature) = + IdSignature.FileSignature( + this, FqName(commonSignature.packageFqName + "." + commonSignature.declarationFqName), "" + ) + private fun FirProperty.getterOrDefault() = getter ?: FirDefaultPropertyGetter( source = null, 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 56dfa2e8fc8..ef104a873fb 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 @@ -7415,6 +7415,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/platformTypes.kt"); } + @Test + @TestMetadata("privateSuperType.kt") + public void testPrivateSuperType() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/privateSuperType.kt"); + } + @Test @TestMetadata("propertyReference.kt") public void testPropertyReference() throws Exception { diff --git a/compiler/testData/codegen/box/compileKotlinAgainstKotlin/privateSuperType.kt b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/privateSuperType.kt new file mode 100644 index 00000000000..0b2ed182583 --- /dev/null +++ b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/privateSuperType.kt @@ -0,0 +1,19 @@ +// MODULE: lib +// FILE: Z.kt +package z + +private interface I { + fun k() = "K" +} + +interface G + +class Z : I, G { + val o = "O" +} + +// MODULE: main(lib) +// FILE: box.kt +import z.Z + +fun box() = Z().run { o + k() } \ No newline at end of file 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 7756305fd70..dd0d83d0112 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 @@ -7301,6 +7301,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/platformTypes.kt"); } + @Test + @TestMetadata("privateSuperType.kt") + public void testPrivateSuperType() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/privateSuperType.kt"); + } + @Test @TestMetadata("propertyReference.kt") public void testPropertyReference() 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 427d04aba2c..da89d534886 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 @@ -7415,6 +7415,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/platformTypes.kt"); } + @Test + @TestMetadata("privateSuperType.kt") + public void testPrivateSuperType() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/privateSuperType.kt"); + } + @Test @TestMetadata("propertyReference.kt") public void testPropertyReference() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java index 3ac7275c4fa..5f73f211f15 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java @@ -397,6 +397,12 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/platformTypes.kt"); } + @Test + @TestMetadata("privateSuperType.kt") + public void testPrivateSuperType() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/privateSuperType.kt"); + } + @Test @TestMetadata("propertyReference.kt") public void testPropertyReference() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java index 4ddfad88c42..9377b0ebc61 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java @@ -397,6 +397,12 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/platformTypes.kt"); } + @Test + @TestMetadata("privateSuperType.kt") + public void testPrivateSuperType() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/privateSuperType.kt"); + } + @Test @TestMetadata("propertyReference.kt") public void testPropertyReference() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 23eb534de27..0d6ba4d6336 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -5605,6 +5605,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/nestedTypeAliasExpansion.kt"); } + @Test + @TestMetadata("privateSuperType.kt") + public void testPrivateSuperType() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/privateSuperType.kt"); + } + @Test @TestMetadata("propertyReference.kt") public void testPropertyReference() throws Exception {