JVM IR: fix name and parent of JvmSymbols.kClassJava

In contrast to other top-level functions/properties declared in
JvmSymbols (unsafeCoerce, signatureString, etc), kClassJava refers to a
real symbol from the library. Since not all calls to it are intrinsified
(see KClassJavaProperty.kt:30), it makes sense to allow to reference it
when constructing IR. For that, it needs to have the correct file facade
as the parent, and the JvmName annotation so that its name is mapped
correctly in the codegen.

Co-authored-by: Leonid Startsev <leonid.startsev@jetbrains.com>
This commit is contained in:
Alexander Udalov
2021-07-09 19:00:31 +02:00
parent d33debdf7c
commit 6f72c681ed
2 changed files with 17 additions and 2 deletions
@@ -689,12 +689,23 @@ class JvmSymbols(
val genericToArray: IrSimpleFunctionSymbol =
collectionToArrayClass.functions.single { it.owner.name.asString() == "toArray" && it.owner.valueParameters.size == 2 }
val jvmName: IrClassSymbol = createClass(FqName("kotlin.jvm.JvmName"), ClassKind.ANNOTATION_CLASS) { klass ->
klass.addConstructor().apply {
addValueParameter("name", irBuiltIns.stringType)
}
}
val kClassJava: IrPropertySymbol =
irFactory.buildProperty {
name = Name.identifier("java")
}.apply {
parent = kotlinJvmPackage
parent = createClass(FqName("kotlin.jvm.JvmClassMappingKt")).owner
addGetter().apply {
annotations = listOf(
IrConstructorCallImpl.fromSymbolOwner(jvmName.typeWith(), jvmName.constructors.single()).apply {
putValueArgument(0, IrConstImpl.string(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irBuiltIns.stringType, "getJavaClass"))
}
)
addExtensionReceiver(irBuiltIns.kClassClass.starProjectedType)
returnType = javaLangClass.starProjectedType
}
@@ -88,7 +88,11 @@ class IrConstructorCallImpl(
return fromSymbolOwner(startOffset, endOffset, type, constructorSymbol, classTypeParametersCount, origin)
}
fun fromSymbolOwner(type: IrType, constructorSymbol: IrConstructorSymbol, origin: IrStatementOrigin? = null) =
fun fromSymbolOwner(
type: IrType,
constructorSymbol: IrConstructorSymbol,
origin: IrStatementOrigin? = null
): IrConstructorCallImpl =
fromSymbolOwner(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, constructorSymbol, constructorSymbol.owner.parentAsClass.typeParameters.size,
origin