From b8b8b7fd3af832766d16ddf4ee16984be0b020ae Mon Sep 17 00:00:00 2001 From: "vladislav.grechko" Date: Tue, 13 Jun 2023 14:55:53 +0200 Subject: [PATCH] [JVM_IR] Move variables out of `IrInlinedFunctionBlock` on MFVC lowering Variables in `IrInlinedFunctionBlock` declared before the composite blocks with arguments evaluation may lead to error on codegen while processing `IrInlinedFunctionBlock`. ^KT-58779: Fixed --- .../backend/jvm/lower/JvmMultiFieldValueClassLowering.kt | 7 +++++++ .../codegen/box/valueClasses/functionReferences.kt | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmMultiFieldValueClassLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmMultiFieldValueClassLowering.kt index 3b1da6a1fad..b2d45746ef9 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmMultiFieldValueClassLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmMultiFieldValueClassLowering.kt @@ -1423,6 +1423,13 @@ private fun findNearestBlocksForVariables(variables: Set, body: Bloc } override fun visitBlock(expression: IrBlock) { + // This is a workaround. + // We process IrInlinedFunctionBlock on codegen in a special way by processing composite blocks with arguments evaluation first. + // Thus, we don't want IrInlinedFunctionBlock to contain variable declarations before this composite blocks. + // That is why we move variable declarations from IrInlinedFunctionBlock to the outer block. + if (expression is IrInlinedFunctionBlock) { + return super.visitBlock(expression) + } currentStackElement()?.let { childrenBlocks.getOrPut(it) { mutableListOf() }.add(Block(expression)) } stack.add(Block(expression)) super.visitBlock(expression) diff --git a/compiler/testData/codegen/box/valueClasses/functionReferences.kt b/compiler/testData/codegen/box/valueClasses/functionReferences.kt index a01f0662482..495d136418b 100644 --- a/compiler/testData/codegen/box/valueClasses/functionReferences.kt +++ b/compiler/testData/codegen/box/valueClasses/functionReferences.kt @@ -2,7 +2,6 @@ // WITH_STDLIB // WITH_COROUTINES // TARGET_BACKEND: JVM_IR -// IGNORE_INLINER: IR // LANGUAGE: +ValueClasses // FIR_IDENTICAL