JVM_IR fix local class names for files with @JvmPackageName
This commit is contained in:
committed by
TeamCityServer
parent
c4b2b7e0da
commit
19fb7ebfd5
+24
@@ -23480,6 +23480,30 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("anonymousObject.kt")
|
||||||
|
public void testAnonymousObject() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("anonymousObjectInInheritedMultifilePart.kt")
|
||||||
|
public void testAnonymousObjectInInheritedMultifilePart() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObjectInInheritedMultifilePart.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("anonymousObjectInMultifilePart.kt")
|
||||||
|
public void testAnonymousObjectInMultifilePart() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObjectInMultifilePart.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("localClass.kt")
|
||||||
|
public void testLocalClass() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/localClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("metadataField.kt")
|
@TestMetadata("metadataField.kt")
|
||||||
public void testMetadataField() throws Exception {
|
public void testMetadataField() throws Exception {
|
||||||
|
|||||||
+19
-9
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.config.LanguageFeature
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
|
import org.jetbrains.kotlin.fileClasses.JvmFileClassInfo
|
||||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
||||||
import org.jetbrains.kotlin.fileClasses.JvmSimpleFileClassInfo
|
import org.jetbrains.kotlin.fileClasses.JvmSimpleFileClassInfo
|
||||||
import org.jetbrains.kotlin.ir.PsiIrFileEntry
|
import org.jetbrains.kotlin.ir.PsiIrFileEntry
|
||||||
@@ -78,13 +79,7 @@ private class FileClassLowering(val context: JvmBackendContext) : FileLoweringPa
|
|||||||
|
|
||||||
private fun createFileClass(irFile: IrFile, fileClassMembers: List<IrDeclaration>): IrClass {
|
private fun createFileClass(irFile: IrFile, fileClassMembers: List<IrDeclaration>): IrClass {
|
||||||
val fileEntry = irFile.fileEntry
|
val fileEntry = irFile.fileEntry
|
||||||
val fileClassInfo = when (fileEntry) {
|
val fileClassInfo = irFile.getFileClassInfo()
|
||||||
is PsiIrFileEntry ->
|
|
||||||
JvmFileClassUtil.getFileClassInfoNoResolve(fileEntry.psiFile as KtFile)
|
|
||||||
is NaiveSourceBasedFileEntryImpl ->
|
|
||||||
JvmSimpleFileClassInfo(PackagePartClassUtils.getPackagePartFqName(irFile.fqName, fileEntry.name), false)
|
|
||||||
else -> error("unknown kind of file entry: $fileEntry")
|
|
||||||
}
|
|
||||||
val isMultifilePart = fileClassInfo.withJvmMultifileClass
|
val isMultifilePart = fileClassInfo.withJvmMultifileClass
|
||||||
|
|
||||||
val onlyPrivateDeclarationsAndFeatureIsEnabled =
|
val onlyPrivateDeclarationsAndFeatureIsEnabled =
|
||||||
@@ -95,10 +90,14 @@ private class FileClassLowering(val context: JvmBackendContext) : FileLoweringPa
|
|||||||
isPrivate || isInlineOnly
|
isPrivate || isInlineOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val fileClassOrigin =
|
||||||
|
if (!isMultifilePart || context.state.languageVersionSettings.getFlag(JvmAnalysisFlags.inheritMultifileParts))
|
||||||
|
IrDeclarationOrigin.FILE_CLASS
|
||||||
|
else
|
||||||
|
IrDeclarationOrigin.SYNTHETIC_FILE_CLASS
|
||||||
return IrClassImpl(
|
return IrClassImpl(
|
||||||
0, fileEntry.maxOffset,
|
0, fileEntry.maxOffset,
|
||||||
if (!isMultifilePart || context.state.languageVersionSettings.getFlag(JvmAnalysisFlags.inheritMultifileParts))
|
fileClassOrigin,
|
||||||
IrDeclarationOrigin.FILE_CLASS else IrDeclarationOrigin.SYNTHETIC_FILE_CLASS,
|
|
||||||
symbol = IrClassSymbolImpl(),
|
symbol = IrClassSymbolImpl(),
|
||||||
name = fileClassInfo.fileClassFqName.shortName(),
|
name = fileClassInfo.fileClassFqName.shortName(),
|
||||||
kind = ClassKind.CLASS,
|
kind = ClassKind.CLASS,
|
||||||
@@ -148,3 +147,14 @@ private class FileClassLowering(val context: JvmBackendContext) : FileLoweringPa
|
|||||||
private val JVM_NAME = IdSignature.PublicSignature("kotlin.jvm", "JvmName", null, 0)
|
private val JVM_NAME = IdSignature.PublicSignature("kotlin.jvm", "JvmName", null, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun IrFile.getFileClassInfo(): JvmFileClassInfo =
|
||||||
|
when (val fileEntry = this.fileEntry) {
|
||||||
|
is PsiIrFileEntry ->
|
||||||
|
JvmFileClassUtil.getFileClassInfoNoResolve(fileEntry.psiFile as KtFile)
|
||||||
|
is NaiveSourceBasedFileEntryImpl ->
|
||||||
|
JvmSimpleFileClassInfo(PackagePartClassUtils.getPackagePartFqName(fqName, fileEntry.name), false)
|
||||||
|
else ->
|
||||||
|
error("unknown kind of file entry: $fileEntry")
|
||||||
|
}
|
||||||
|
|||||||
+14
-6
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.expressions.IrFunctionReference
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
|
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.util.isAnonymousObject
|
import org.jetbrains.kotlin.ir.util.isAnonymousObject
|
||||||
|
import org.jetbrains.kotlin.ir.util.render
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.name.NameUtils
|
import org.jetbrains.kotlin.name.NameUtils
|
||||||
@@ -54,15 +55,22 @@ class InventNamesForLocalClasses(private val context: JvmBackendContext) : FileL
|
|||||||
if (!data.isLocal) {
|
if (!data.isLocal) {
|
||||||
// This is not a local class, so we need not invent a name for it, the type mapper will correctly compute it
|
// This is not a local class, so we need not invent a name for it, the type mapper will correctly compute it
|
||||||
// by navigating through its containers.
|
// by navigating through its containers.
|
||||||
|
val enclosingName = data.enclosingName
|
||||||
val internalName = data.enclosingName?.let { enclosingName ->
|
val internalName = if (enclosingName != null) {
|
||||||
"$enclosingName$${declaration.name.asString()}"
|
"$enclosingName$${declaration.name.asString()}"
|
||||||
} ?: (declaration.parent as IrFile).let { file ->
|
} else {
|
||||||
JvmClassName.byFqNameWithoutInnerClasses(file.fqName.child(declaration.name)).internalName
|
val file = declaration.parent as? IrFile
|
||||||
|
?: throw AssertionError("Top-level class expected: ${declaration.render()}")
|
||||||
|
val classFqn =
|
||||||
|
if (declaration.origin == IrDeclarationOrigin.FILE_CLASS ||
|
||||||
|
declaration.origin == IrDeclarationOrigin.SYNTHETIC_FILE_CLASS
|
||||||
|
)
|
||||||
|
file.getFileClassInfo().fileClassFqName
|
||||||
|
else
|
||||||
|
file.fqName.child(declaration.name)
|
||||||
|
JvmClassName.byFqNameWithoutInnerClasses(classFqn).internalName
|
||||||
}
|
}
|
||||||
|
|
||||||
declaration.acceptChildren(this, data.withName(internalName))
|
declaration.acceptChildren(this, data.withName(internalName))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// IGNORE_FIR_DIAGNOSTICS
|
||||||
|
|
||||||
|
// Duplicate JVM class name 'xx/ZKt'
|
||||||
|
// IGNORE_BACKEND: ANDROID
|
||||||
|
|
||||||
|
// FILE: anonymousObject.kt
|
||||||
|
import x.*
|
||||||
|
|
||||||
|
fun box(): String =
|
||||||
|
"O".z().toString() +
|
||||||
|
"K".iz().toString()
|
||||||
|
|
||||||
|
// FILE: z.kt
|
||||||
|
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||||
|
@file:kotlin.jvm.JvmPackageName("xx")
|
||||||
|
package x
|
||||||
|
|
||||||
|
fun String.z(): Any {
|
||||||
|
return object {
|
||||||
|
override fun toString(): String =
|
||||||
|
this@z
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun String.iz(): Any {
|
||||||
|
return object {
|
||||||
|
override fun toString(): String =
|
||||||
|
this@iz
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// IGNORE_FIR_DIAGNOSTICS
|
||||||
|
// IGNORE_LIGHT_ANALYSIS
|
||||||
|
|
||||||
|
// Duplicate JVM class name 'xx/ZKt'
|
||||||
|
// IGNORE_BACKEND: ANDROID
|
||||||
|
|
||||||
|
// !INHERIT_MULTIFILE_PARTS
|
||||||
|
|
||||||
|
// FILE: anonymousObject.kt
|
||||||
|
import x.*
|
||||||
|
|
||||||
|
fun box(): String =
|
||||||
|
"O".z().toString() +
|
||||||
|
"K".iz().toString()
|
||||||
|
|
||||||
|
// FILE: z.kt
|
||||||
|
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||||
|
@file:kotlin.jvm.JvmMultifileClass
|
||||||
|
@file:kotlin.jvm.JvmName("ZKt")
|
||||||
|
@file:kotlin.jvm.JvmPackageName("xx")
|
||||||
|
package x
|
||||||
|
|
||||||
|
fun String.z(): Any {
|
||||||
|
return object {
|
||||||
|
override fun toString(): String =
|
||||||
|
this@z
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: z2.kt
|
||||||
|
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||||
|
@file:kotlin.jvm.JvmMultifileClass
|
||||||
|
@file:kotlin.jvm.JvmName("ZKt")
|
||||||
|
@file:kotlin.jvm.JvmPackageName("xx")
|
||||||
|
package x
|
||||||
|
|
||||||
|
inline fun String.iz(): Any {
|
||||||
|
return object {
|
||||||
|
override fun toString(): String =
|
||||||
|
this@iz
|
||||||
|
}
|
||||||
|
}
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// IGNORE_FIR_DIAGNOSTICS
|
||||||
|
|
||||||
|
// Duplicate JVM class name 'xx/ZKt'
|
||||||
|
// IGNORE_BACKEND: ANDROID
|
||||||
|
|
||||||
|
// FILE: anonymousObject.kt
|
||||||
|
import x.*
|
||||||
|
|
||||||
|
fun box(): String =
|
||||||
|
"O".z().toString() +
|
||||||
|
"K".iz().toString()
|
||||||
|
|
||||||
|
// FILE: z.kt
|
||||||
|
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||||
|
@file:kotlin.jvm.JvmMultifileClass
|
||||||
|
@file:kotlin.jvm.JvmName("ZKt")
|
||||||
|
@file:kotlin.jvm.JvmPackageName("xx")
|
||||||
|
package x
|
||||||
|
|
||||||
|
fun String.z(): Any {
|
||||||
|
return object {
|
||||||
|
override fun toString(): String =
|
||||||
|
this@z
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: z2.kt
|
||||||
|
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||||
|
@file:kotlin.jvm.JvmMultifileClass
|
||||||
|
@file:kotlin.jvm.JvmName("ZKt")
|
||||||
|
@file:kotlin.jvm.JvmPackageName("xx")
|
||||||
|
package x
|
||||||
|
|
||||||
|
inline fun String.iz(): Any {
|
||||||
|
return object {
|
||||||
|
override fun toString(): String =
|
||||||
|
this@iz
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// IGNORE_FIR_DIAGNOSTICS
|
||||||
|
|
||||||
|
// Duplicate JVM class name 'xx/ZKt'
|
||||||
|
// IGNORE_BACKEND: ANDROID
|
||||||
|
|
||||||
|
// FILE: anonymousObject.kt
|
||||||
|
import x.*
|
||||||
|
|
||||||
|
fun box(): String =
|
||||||
|
"OK".z().toString()
|
||||||
|
|
||||||
|
// FILE: z.kt
|
||||||
|
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||||
|
@file:kotlin.jvm.JvmPackageName("xx")
|
||||||
|
package x
|
||||||
|
|
||||||
|
fun String.z(): Any {
|
||||||
|
class Local {
|
||||||
|
override fun toString(): String =
|
||||||
|
this@z
|
||||||
|
}
|
||||||
|
|
||||||
|
return Local()
|
||||||
|
}
|
||||||
+24
@@ -23462,6 +23462,30 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("anonymousObject.kt")
|
||||||
|
public void testAnonymousObject() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("anonymousObjectInInheritedMultifilePart.kt")
|
||||||
|
public void testAnonymousObjectInInheritedMultifilePart() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObjectInInheritedMultifilePart.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("anonymousObjectInMultifilePart.kt")
|
||||||
|
public void testAnonymousObjectInMultifilePart() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObjectInMultifilePart.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("localClass.kt")
|
||||||
|
public void testLocalClass() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/localClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("metadataField.kt")
|
@TestMetadata("metadataField.kt")
|
||||||
public void testMetadataField() throws Exception {
|
public void testMetadataField() throws Exception {
|
||||||
|
|||||||
+24
@@ -23480,6 +23480,30 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("anonymousObject.kt")
|
||||||
|
public void testAnonymousObject() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("anonymousObjectInInheritedMultifilePart.kt")
|
||||||
|
public void testAnonymousObjectInInheritedMultifilePart() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObjectInInheritedMultifilePart.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("anonymousObjectInMultifilePart.kt")
|
||||||
|
public void testAnonymousObjectInMultifilePart() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObjectInMultifilePart.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("localClass.kt")
|
||||||
|
public void testLocalClass() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/localClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("metadataField.kt")
|
@TestMetadata("metadataField.kt")
|
||||||
public void testMetadataField() throws Exception {
|
public void testMetadataField() throws Exception {
|
||||||
|
|||||||
+20
@@ -19771,6 +19771,26 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("anonymousObject.kt")
|
||||||
|
public void testAnonymousObject() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("anonymousObjectInInheritedMultifilePart.kt")
|
||||||
|
public void testAnonymousObjectInInheritedMultifilePart() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObjectInInheritedMultifilePart.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("anonymousObjectInMultifilePart.kt")
|
||||||
|
public void testAnonymousObjectInMultifilePart() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/anonymousObjectInMultifilePart.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("localClass.kt")
|
||||||
|
public void testLocalClass() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmPackageName/localClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("metadataField.kt")
|
@TestMetadata("metadataField.kt")
|
||||||
public void testMetadataField() throws Exception {
|
public void testMetadataField() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/jvmPackageName/metadataField.kt");
|
runTest("compiler/testData/codegen/box/jvmPackageName/metadataField.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user