[FIR] Fix naming of local classes when serializing metadata
^KT-63655: Fixed ^KT-63901: Fixed ^KT-63988: Fixed
This commit is contained in:
committed by
Space Team
parent
78876b32e9
commit
54858c2118
+12
@@ -45880,6 +45880,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
|
||||
runTest("compiler/testData/codegen/box/reflection/jvmKTypeCaching.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt63988.kt")
|
||||
public void testKt63988() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/kt63988.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -47860,6 +47866,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
|
||||
public void testLocalClassesAndAnonymousObjects() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localClassesAndAnonymousObjects.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localNestedClasses.kt")
|
||||
public void testLocalNestedClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localNestedClasses.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+12
@@ -45880,6 +45880,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
|
||||
runTest("compiler/testData/codegen/box/reflection/jvmKTypeCaching.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt63988.kt")
|
||||
public void testKt63988() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/kt63988.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -47860,6 +47866,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
|
||||
public void testLocalClassesAndAnonymousObjects() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localClassesAndAnonymousObjects.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localNestedClasses.kt")
|
||||
public void testLocalNestedClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localNestedClasses.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+28
-7
@@ -6,31 +6,52 @@
|
||||
package org.jetbrains.kotlin.fir.backend.jvm
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.mapping.IrTypeMapper
|
||||
import org.jetbrains.kotlin.backend.jvm.mapping.mapClass
|
||||
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.serialization.FirElementAwareStringTable
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmNameResolver
|
||||
import org.jetbrains.kotlin.metadata.jvm.serialization.JvmStringTable
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirJvmElementAwareStringTable(
|
||||
private val typeMapper: IrTypeMapper,
|
||||
private val components: Fir2IrComponents,
|
||||
private val localPoppedUpClasses: List<IrAttributeContainer>,
|
||||
nameResolver: JvmNameResolver? = null
|
||||
) : JvmStringTable(nameResolver), FirElementAwareStringTable {
|
||||
override fun getLocalClassIdReplacement(firClass: FirClass): ClassId =
|
||||
components.classifierStorage.getCachedIrClass(firClass)?.getLocalClassIdReplacement()
|
||||
?: throw AssertionError("not a local class: ${firClass.symbol.classId}")
|
||||
|
||||
private fun IrClass.getLocalClassIdReplacement(): ClassId =
|
||||
when (val parent = parent) {
|
||||
is IrClass -> parent.getLocalClassIdReplacement().createNestedClassId(name)
|
||||
else -> {
|
||||
val fqName = FqName(typeMapper.mapClass(this).internalName.replace('/', '.'))
|
||||
ClassId(fqName.parent(), FqName.topLevel(fqName.shortName()), isLocal = true)
|
||||
private fun IrClass.getLocalClassIdReplacement(): ClassId {
|
||||
// This convoluted implementation aims to reproduce K1 behaviour (see JvmCodegenStringTable::getLocalClassIdReplacement).
|
||||
// K1 uses both '.' and '$' to separate nested class names when serializing metadata.
|
||||
// That does not make much sense and looks like an artifact of implementation arising from K1 descriptors structure.
|
||||
// But we still need to preserve it to establish compatibility with K2-produced metadata.
|
||||
|
||||
val thisClassName = typeMapper.classInternalName(this).replace('/', '.')
|
||||
if (attributeOwnerId in localPoppedUpClasses) {
|
||||
// For those classes, whose original parent has been changed on the lowering stage.
|
||||
// In K1, the `containingDeclaration` of such class descriptor would be the original declaration: constructor or property.
|
||||
// Thus, this case corresponds to the `else` branch of JvmCodegenStringTable::getLocalClassIdReplacement.
|
||||
val thisClassFqName = FqName(thisClassName)
|
||||
return ClassId(thisClassFqName.parent(), FqName.topLevel(thisClassFqName.shortName()), isLocal = true)
|
||||
} else {
|
||||
// Otherwise, find topmost class parent. Its name will have '$' as delimiter
|
||||
val topmostClassParent = generateSequence(this) { it.parent as? IrClass }.last()
|
||||
val topmostClassParentName = typeMapper.classInternalName(topmostClassParent).replace('/', '.')
|
||||
val prefixFqName = FqName(topmostClassParentName)
|
||||
var classId = ClassId(prefixFqName.parent(), FqName.topLevel(prefixFqName.shortName()), isLocal = true)
|
||||
if (thisClassName.length == topmostClassParentName.length) return classId
|
||||
// The remaining part uses '.'
|
||||
thisClassName.substring(topmostClassParentName.length + 1).split('$').forEach {
|
||||
classId = classId.createNestedClassId(Name.identifier(it))
|
||||
}
|
||||
return classId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-4
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.fir.serialization.FirElementSerializer
|
||||
import org.jetbrains.kotlin.fir.serialization.FirSerializerExtension
|
||||
import org.jetbrains.kotlin.fir.serialization.constant.ConstValueProvider
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer
|
||||
import org.jetbrains.kotlin.ir.declarations.MetadataSource
|
||||
import org.jetbrains.kotlin.load.kotlin.NON_EXISTENT_CLASS_NAME
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
@@ -77,14 +78,27 @@ class FirJvmSerializerExtension(
|
||||
state: GenerationState,
|
||||
metadata: MetadataSource?,
|
||||
localDelegatedProperties: List<FirProperty>,
|
||||
localPoppedUpClasses: List<IrAttributeContainer>,
|
||||
approximator: AbstractTypeApproximator,
|
||||
typeMapper: IrTypeMapper,
|
||||
components: Fir2IrComponents
|
||||
) : this(
|
||||
session, bindings, metadata, localDelegatedProperties, approximator, components.scopeSession,
|
||||
state.globalSerializationBindings, state.config.useTypeTableInSerializer, state.moduleName, state.classBuilderMode,
|
||||
state.config.isParamAssertionsDisabled, state.config.unifiedNullChecks, state.config.metadataVersion, state.jvmDefaultMode,
|
||||
FirJvmElementAwareStringTable(typeMapper, components), ConstValueProviderImpl(components),
|
||||
session,
|
||||
bindings,
|
||||
metadata,
|
||||
localDelegatedProperties,
|
||||
approximator,
|
||||
components.scopeSession,
|
||||
state.globalSerializationBindings,
|
||||
state.config.useTypeTableInSerializer,
|
||||
state.moduleName,
|
||||
state.classBuilderMode,
|
||||
state.config.isParamAssertionsDisabled,
|
||||
state.config.unifiedNullChecks,
|
||||
state.config.metadataVersion,
|
||||
state.jvmDefaultMode,
|
||||
FirJvmElementAwareStringTable(typeMapper, components, localPoppedUpClasses),
|
||||
ConstValueProviderImpl(components),
|
||||
components.annotationsFromPluginRegistrar.createAdditionalMetadataProvider()
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ fun makeFirMetadataSerializerForIrClass(
|
||||
(it.owner.metadata as? FirMetadataSource.Property)?.fir?.copyToFreeProperty(approximator)
|
||||
} ?: emptyList()
|
||||
val firSerializerExtension = FirJvmSerializerExtension(
|
||||
session, serializationBindings, context.state, irClass.metadata, localDelegatedProperties,
|
||||
session, serializationBindings, context.state, irClass.metadata, localDelegatedProperties, context.isEnclosedInConstructor.toList(),
|
||||
approximator, context.defaultTypeMapper, components
|
||||
)
|
||||
return FirMetadataSerializer(
|
||||
|
||||
+12
@@ -45477,6 +45477,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/reflection/jvmKTypeCaching.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt63988.kt")
|
||||
public void testKt63988() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/kt63988.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -47451,6 +47457,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
public void testLocalClassesAndAnonymousObjects() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localClassesAndAnonymousObjects.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localNestedClasses.kt")
|
||||
public void testLocalNestedClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localNestedClasses.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+12
@@ -45477,6 +45477,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
runTest("compiler/testData/codegen/box/reflection/jvmKTypeCaching.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt63988.kt")
|
||||
public void testKt63988() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/kt63988.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -47451,6 +47457,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
public void testLocalClassesAndAnonymousObjects() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localClassesAndAnonymousObjects.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localNestedClasses.kt")
|
||||
public void testLocalNestedClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localNestedClasses.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+12
@@ -45477,6 +45477,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/reflection/jvmKTypeCaching.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt63988.kt")
|
||||
public void testKt63988() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/kt63988.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -47451,6 +47457,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
public void testLocalClassesAndAnonymousObjects() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localClassesAndAnonymousObjects.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localNestedClasses.kt")
|
||||
public void testLocalNestedClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localNestedClasses.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS Outer$foo$Local.class
|
||||
CLASS METADATA
|
||||
PROPERTY getObj()LOuter$foo$Local$obj$1;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.Outer$foo$Local$obj$1
|
||||
K2
|
||||
.Outer$foo$Local.<no name provided>
|
||||
@@ -1,5 +1,3 @@
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63868
|
||||
|
||||
fun <R> run(block: () -> R) = block()
|
||||
inline fun <R> inlineRun(block: () -> R) = block()
|
||||
|
||||
|
||||
Vendored
-9
@@ -1,9 +0,0 @@
|
||||
MODULE lib
|
||||
CLASS A.class
|
||||
CLASS METADATA
|
||||
PROPERTY x
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.A$x$1
|
||||
K2
|
||||
.A.<no name provided>
|
||||
-1
@@ -1,6 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// MODULE: lib
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63868
|
||||
|
||||
// FILE: A.kt
|
||||
abstract class A {
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS ObjectExtendsInnerOfLocalVarargAndDefaultKt$box$Local.class
|
||||
CLASS METADATA
|
||||
PROPERTY getObj()LObjectExtendsInnerOfLocalVarargAndDefaultKt$box$Local$obj$1;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.ObjectExtendsInnerOfLocalVarargAndDefaultKt$box$Local$obj$1
|
||||
K2
|
||||
.ObjectExtendsInnerOfLocalVarargAndDefaultKt$box$Local.<no name provided>
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
fun box(): String {
|
||||
val capture = "oh"
|
||||
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS ObjectExtendsInnerOfLocalWithCaptureKt$box$Local.class
|
||||
CLASS METADATA
|
||||
PROPERTY getObj()LObjectExtendsInnerOfLocalWithCaptureKt$box$Local$obj$1;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.ObjectExtendsInnerOfLocalWithCaptureKt$box$Local$obj$1
|
||||
K2
|
||||
.ObjectExtendsInnerOfLocalWithCaptureKt$box$Local.<no name provided>
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
fun box(): String {
|
||||
class Local {
|
||||
open inner class Inner(val s: String) {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS A.class
|
||||
CLASS METADATA
|
||||
PROPERTY b
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.A$b$1
|
||||
K2
|
||||
.A.<no name provided>
|
||||
@@ -1,6 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
|
||||
// FILE: kt43217.kt
|
||||
|
||||
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
MODULE main
|
||||
CLASS A$o$1.class
|
||||
CLASS METADATA
|
||||
Property: class.metadata.superTypes
|
||||
K1
|
||||
[.A$B]
|
||||
K2
|
||||
[.A.B]
|
||||
@@ -1,5 +1,3 @@
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63901
|
||||
|
||||
class A {
|
||||
var a: String = "Fail"
|
||||
|
||||
|
||||
Vendored
-9
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS CompoundAssignmentToPropertyWithQualifierKt$box$c$1.class
|
||||
CLASS METADATA
|
||||
PROPERTY getB()LCompoundAssignmentToPropertyWithQualifierKt$box$c$1$b$1;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.CompoundAssignmentToPropertyWithQualifierKt$box$c$1$b$1
|
||||
K2
|
||||
.CompoundAssignmentToPropertyWithQualifierKt$box$c$1.<no name provided>
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
|
||||
var log = ""
|
||||
|
||||
class A(p: String) {
|
||||
|
||||
@@ -7,12 +7,6 @@ MODULE main
|
||||
java/util/ArrayList<kotlin/String> /* = kotlin/collections/ArrayList^<kotlin/String> */
|
||||
K2
|
||||
java/util/ArrayList<kotlin/String>
|
||||
PROPERTY workerThread
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.SomeClass$workerThread$1
|
||||
K2
|
||||
.SomeClass.<no name provided>
|
||||
CLASS SomeClass$Inner.class
|
||||
CLASS METADATA
|
||||
PROPERTY getCopy()Ljava/util/ArrayList;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655, KT-63864
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
public object SomeObject {
|
||||
private val workerThread = object : Thread() {
|
||||
override fun run() {
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS ObjectInLocalAnonymousObjectKt$box$foo$1.class
|
||||
CLASS METADATA
|
||||
PROPERTY getBar()LObjectInLocalAnonymousObjectKt$box$foo$1$bar$1;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.ObjectInLocalAnonymousObjectKt$box$foo$1$bar$1
|
||||
K2
|
||||
.ObjectInLocalAnonymousObjectKt$box$foo$1.<no name provided>
|
||||
@@ -1,4 +1,3 @@
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
fun box(): String {
|
||||
var boo = "OK"
|
||||
var foo = object {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS C.class
|
||||
CLASS METADATA
|
||||
PROPERTY localObject
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.C$localObject$1
|
||||
K2
|
||||
.C.<no name provided>
|
||||
@@ -1,4 +1,3 @@
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
class C {
|
||||
|
||||
val s = "OK"
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS Outer.class
|
||||
CLASS METADATA
|
||||
PROPERTY obj
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.Outer$obj$1
|
||||
K2
|
||||
.Outer.<no name provided>
|
||||
@@ -1,5 +1,4 @@
|
||||
// KT-44054
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
enum class Enum {
|
||||
Entry1,
|
||||
Entry2
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
MODULE main
|
||||
CLASS Outer.class
|
||||
CLASS METADATA
|
||||
PROPERTY obj1
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.Outer$obj1$1
|
||||
K2
|
||||
.Outer.<no name provided>
|
||||
PROPERTY obj2
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.Outer$obj2$1
|
||||
K2
|
||||
.Outer.<no name provided>
|
||||
@@ -1,6 +1,4 @@
|
||||
// KT-44050
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
|
||||
enum class Enum {
|
||||
Entry1() {
|
||||
fun bogus() = 42
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS InvokeKt$box$o$1.class
|
||||
CLASS METADATA
|
||||
PROPERTY getP()LInvokeKt$box$o$1$p$1;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.InvokeKt$box$o$1$p$1
|
||||
K2
|
||||
.InvokeKt$box$o$1.<no name provided>
|
||||
@@ -3,7 +3,6 @@
|
||||
// FULL_JDK
|
||||
// SKIP_JDK6
|
||||
// WITH_STDLIB
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
|
||||
import java.lang.invoke.MethodHandles
|
||||
import java.lang.invoke.MethodType
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.full.memberProperties
|
||||
|
||||
class A {
|
||||
val prop = object {
|
||||
val nestedProp = object {}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = if (A().prop::class.memberProperties.size == 1) "OK" else "Fail"
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
MODULE main
|
||||
CLASS LocalNestedClassesKt$foo1$X$Y.class
|
||||
CLASS METADATA
|
||||
Property: class.metadata.companionObject
|
||||
K1
|
||||
null
|
||||
K2
|
||||
Z
|
||||
CLASS LocalNestedClassesKt$foo2$X$Y.class
|
||||
CLASS METADATA
|
||||
Property: class.metadata.companionObject
|
||||
K1
|
||||
null
|
||||
K2
|
||||
Companion
|
||||
@@ -0,0 +1,144 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_REFLECT
|
||||
// JVM_ABI_K1_K2_DIFF: K2 names companion objects in metadata correctly
|
||||
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.full.memberProperties
|
||||
|
||||
val KType.str get() = classifier.toString()
|
||||
|
||||
class A {
|
||||
fun foo(): String {
|
||||
class Nested {
|
||||
inner class Inner {
|
||||
val prop = this
|
||||
}
|
||||
}
|
||||
return Nested().Inner()::class.memberProperties.iterator().next().returnType.str
|
||||
}
|
||||
}
|
||||
|
||||
fun foo1(): String {
|
||||
class X {
|
||||
inner class Y {
|
||||
companion object Z
|
||||
|
||||
val prop = Z
|
||||
}
|
||||
}
|
||||
return X.Y::class.memberProperties.iterator().next().returnType.str
|
||||
}
|
||||
|
||||
fun foo2(): String {
|
||||
class X {
|
||||
inner class Y {
|
||||
companion object
|
||||
|
||||
val prop = Companion
|
||||
}
|
||||
}
|
||||
return X.Y::class.memberProperties.iterator().next().returnType.str
|
||||
}
|
||||
|
||||
fun foo3(): String {
|
||||
class X {
|
||||
inner class Y {
|
||||
val prop = object {}
|
||||
}
|
||||
}
|
||||
return X.Y::class.memberProperties.iterator().next().returnType.str
|
||||
}
|
||||
|
||||
fun foo4(): String {
|
||||
var res = ""
|
||||
|
||||
class A {
|
||||
inner class B {
|
||||
inner class C {
|
||||
fun bar() {
|
||||
class D {
|
||||
val prop = this
|
||||
}
|
||||
res = D::class.memberProperties.iterator().next().returnType.str
|
||||
}
|
||||
|
||||
init {
|
||||
bar()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
A().B().C()
|
||||
return res
|
||||
}
|
||||
|
||||
fun foo5(): String {
|
||||
var res = ""
|
||||
object {
|
||||
fun bar() {
|
||||
return object {
|
||||
fun foo() {
|
||||
class A {
|
||||
inner class B {
|
||||
val prop = this
|
||||
init {
|
||||
res = prop::class.memberProperties.iterator().next().returnType.str
|
||||
}
|
||||
}
|
||||
}
|
||||
A().B()
|
||||
}
|
||||
}.foo()
|
||||
}
|
||||
}.bar()
|
||||
return res
|
||||
}
|
||||
|
||||
fun foo6(): String {
|
||||
var res = ""
|
||||
object {
|
||||
fun bar() {
|
||||
class A {
|
||||
inner class B {
|
||||
inner class C {
|
||||
val prop = this
|
||||
|
||||
init {
|
||||
res = prop::class.memberProperties.iterator().next().returnType.str
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
A().B().C()
|
||||
}
|
||||
}.bar()
|
||||
return res
|
||||
}
|
||||
|
||||
fun foo7(): String {
|
||||
var res = ""
|
||||
val x = object {
|
||||
val y = object {
|
||||
val z = object {
|
||||
val y = this
|
||||
init {
|
||||
res = this::class.memberProperties.iterator().next().returnType.str
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (A().foo() != "class A\$foo\$Nested\$Inner") return "Fail 1"
|
||||
if (foo1() != "class LocalNestedClassesKt\$foo1\$X\$Y\$Z") return "Fail 2"
|
||||
if (foo2() != "class LocalNestedClassesKt\$foo2\$X\$Y\$Companion") return "Fail 3"
|
||||
if (foo3() != "class LocalNestedClassesKt\$foo3\$X\$Y\$prop\$1") return "Fail 4"
|
||||
if (foo4() != "class LocalNestedClassesKt\$foo4\$A\$B\$C\$bar\$D") return "Fail 5"
|
||||
if (foo5() != "class LocalNestedClassesKt\$foo5\$1\$bar\$1\$foo\$A\$B") return "Fail 6"
|
||||
if (foo6() != "class LocalNestedClassesKt\$foo6\$1\$bar\$A\$B\$C") return "Fail 7"
|
||||
if (foo7() != "class LocalNestedClassesKt\$foo7\$x\$1\$y\$1\$z\$1") return "Fail 8"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS One.class
|
||||
CLASS METADATA
|
||||
PROPERTY getA1()[LOne$a1$1;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
kotlin/Array<.One$a1$1>
|
||||
K2
|
||||
kotlin/Array<.One.<no name provided>>
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
// In light analysis mode, anonymous object type is approximated to the supertype, so `fy` is unresolved.
|
||||
// IGNORE_LIGHT_ANALYSIS
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
|
||||
private class One {
|
||||
val a1 = arrayOf(
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS ObjectExtendsLocalInnerKt$box$Local.class
|
||||
CLASS METADATA
|
||||
PROPERTY getObj()LObjectExtendsLocalInnerKt$box$Local$obj$1;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.ObjectExtendsLocalInnerKt$box$Local$obj$1
|
||||
K2
|
||||
.ObjectExtendsLocalInnerKt$box$Local.<no name provided>
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
fun box(): String {
|
||||
val capture = "O"
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
MODULE main
|
||||
CLASS A.class
|
||||
CLASS METADATA
|
||||
PROPERTY b
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
.A$b$1
|
||||
K2
|
||||
.A.<no name provided>
|
||||
@@ -1,5 +1,4 @@
|
||||
// JVM_TARGET: 1.8
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63655
|
||||
|
||||
// FILE: kt43217.kt
|
||||
class A {
|
||||
|
||||
+12
@@ -44793,6 +44793,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency
|
||||
runTest("compiler/testData/codegen/box/reflection/jvmKTypeCaching.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt63988.kt")
|
||||
public void testKt63988() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/kt63988.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -46767,6 +46773,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency
|
||||
public void testLocalClassesAndAnonymousObjects() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localClassesAndAnonymousObjects.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localNestedClasses.kt")
|
||||
public void testLocalNestedClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localNestedClasses.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+12
@@ -44793,6 +44793,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/reflection/jvmKTypeCaching.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt63988.kt")
|
||||
public void testKt63988() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/kt63988.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -46767,6 +46773,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
public void testLocalClassesAndAnonymousObjects() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localClassesAndAnonymousObjects.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localNestedClasses.kt")
|
||||
public void testLocalNestedClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localNestedClasses.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+12
@@ -44793,6 +44793,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/reflection/jvmKTypeCaching.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt63988.kt")
|
||||
public void testKt63988() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/kt63988.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -46767,6 +46773,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
public void testLocalClassesAndAnonymousObjects() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localClassesAndAnonymousObjects.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localNestedClasses.kt")
|
||||
public void testLocalNestedClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localNestedClasses.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+10
@@ -35564,6 +35564,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/reflection/jvmKTypeCaching.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt63988.kt")
|
||||
public void testKt63988() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/kt63988.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -37324,6 +37329,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
public void testLocalClassesAndAnonymousObjects() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localClassesAndAnonymousObjects.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localNestedClasses.kt")
|
||||
public void testLocalNestedClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/localClasses/localNestedClasses.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/mapping")
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE K2
|
||||
// ^ KT-63655 K2: incorrect short class name in metadata for anonymous object inside a local class
|
||||
|
||||
fun test() {
|
||||
class Local {
|
||||
|
||||
+2
-2
@@ -9,13 +9,13 @@ public final class A : kotlin/Any {
|
||||
}
|
||||
// A$L.class
|
||||
// ------------------------------------------
|
||||
local final class .A.L<T#0 /* T */> : kotlin/Any {
|
||||
local final class .A$L<T#0 /* T */> : kotlin/Any {
|
||||
|
||||
// signature: <init>()V
|
||||
public constructor()
|
||||
|
||||
// signature: x(LA$L;)V
|
||||
public final fun x(l: .A.L<.A.L.I>): kotlin/Unit
|
||||
public final fun x(l: .A$L<.A.L.I>): kotlin/Unit
|
||||
|
||||
// nested class: I
|
||||
|
||||
|
||||
Reference in New Issue
Block a user