Avoid irGet with Unit value if it is last it IrReturnableBlock

This is needed to pass `MethodVerifier` check on JVM backend
This commit is contained in:
Ivan Kylchik
2022-01-27 19:38:04 +03:00
committed by Space Team
parent 707c5f03b8
commit 6e690f709e
@@ -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)
}
}
}
}