diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt index 925dce21fdf..eff972737b2 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt @@ -140,7 +140,7 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F ) valueMap[constructor.constructedClass.thisReceiver!!.symbol] = thisVar - constructor.body?.contents?.forEach { statement -> + constructor.body?.statements?.forEach { statement -> +statement .transform(object : IrElementTransformerVoid() { // Don't recurse under nested class declarations @@ -213,14 +213,6 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F } } - private fun buildReplacementCall( - originalFunction: IrFunction, - original: IrFunctionAccessExpression, - replacement: IrReplacementFunction - ) = context.createIrBuilder(original.symbol) - .irCall(replacement.function) - .apply { buildReplacement(originalFunction, original, replacement) } - override fun visitFunctionReference(expression: IrFunctionReference): IrExpression { val replacement = manager.getReplacementFunction(expression.symbol.owner) ?: return super.visitFunctionReference(expression) @@ -240,7 +232,9 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F val function = expression.symbol.owner val replacement = manager.getReplacementFunction(function) ?: return super.visitFunctionAccess(expression) - return buildReplacementCall(function, expression, replacement) + return context.createIrBuilder(expression.symbol).irCall(replacement.function).apply { + buildReplacement(function, expression, replacement) + } } private fun coerceInlineClasses(argument: IrExpression, from: IrType, to: IrType) = @@ -377,11 +371,3 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F irClass.declarations += function } } - -private val IrBody.contents: List - get() = when (this) { - is IrBlockBody -> statements - is IrExpressionBody -> listOf(expression) - is IrSyntheticBody -> error("Synthetic body contains no statements $this") - else -> throw IllegalStateException() - } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt index 3f471ae65c8..1e1808e083b 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.ir.util import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.IrElement +import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns @@ -198,6 +199,14 @@ val IrDeclarationContainer.properties: Sequence val IrFunction.explicitParameters: List get() = (listOfNotNull(dispatchReceiverParameter, extensionReceiverParameter) + valueParameters) +val IrBody.statements: List + get() = when (this) { + is IrBlockBody -> statements + is IrExpressionBody -> listOf(expression) + is IrSyntheticBody -> error("Synthetic body contains no statements $this") + else -> error("Unknown subclass of IrBody") + } + val IrClass.defaultType: IrSimpleType get() = this.thisReceiver!!.type as IrSimpleType