From 6e690f709eb03669db3a463847edee6eeb8b23d8 Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Thu, 27 Jan 2022 19:38:04 +0300 Subject: [PATCH] Avoid `irGet` with `Unit` value if it is last it `IrReturnableBlock` This is needed to pass `MethodVerifier` check on JVM backend --- .../kotlin/backend/common/lower/ReturnableBlockLowering.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt index 5f4f5f2f489..f4f379bba59 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrDoWhileLoopImpl import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.transformStatement +import org.jetbrains.kotlin.ir.types.isUnit // TODO migrate other usages and move this file to backend.jvm /** @@ -158,7 +159,11 @@ class ReturnableBlockTransformer(val context: CommonBackendContext, val containe return builder.irBlock(expression, expression.origin) { +variable +loop - +irGet(variable) + if (!expression.type.isUnit()) { + // In case of Unit return type we don't need to return an explicit value. This will not be optimized by JVM backend and + // may result in exceptions in `MethodVerifier` before optimizations. + +irGet(variable) + } } } }