IR: use inlineClassRepresentation in getInlineClassUnderlyingType

Looking for the primary constructor manually doesn't work if it's
private in the other module on JVM, because private declarations are
skipped in IrLazyClass.
This commit is contained in:
Alexander Udalov
2021-08-12 13:13:26 +02:00
parent 66dbd91851
commit 8d4f26cf84
13 changed files with 88 additions and 14 deletions
@@ -6,18 +6,13 @@
package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrConstructor
import org.jetbrains.kotlin.ir.declarations.IrField
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.IrSimpleType
fun getInlineClassUnderlyingType(irClass: IrClass): IrType {
for (declaration in irClass.declarations) {
if (declaration is IrConstructor && declaration.isPrimary) {
return declaration.valueParameters[0].type
}
}
error("Inline class has no primary constructor: ${irClass.fqNameWhenAvailable}")
fun getInlineClassUnderlyingType(irClass: IrClass): IrSimpleType {
val representation = irClass.inlineClassRepresentation ?: error("Not an inline class: ${irClass.render()}")
return representation.underlyingType
}
fun getInlineClassBackingField(irClass: IrClass): IrField {