Native: RedundantCoercionsCleaner should rewrite nested returns too

This commit is contained in:
Svyatoslav Scherbina
2021-08-25 16:19:41 +03:00
committed by Space
parent 3176dd1341
commit 981a6ffeb8
3 changed files with 23 additions and 1 deletions
@@ -163,10 +163,11 @@ internal class RedundantCoercionsCleaner(val context: Context) : FileLoweringPas
}
transformedReturnableBlock.transformChildrenVoid(object: IrElementTransformerVoid() {
override fun visitExpression(expression: IrExpression): IrExpression {
expression.transformChildrenVoid()
foldedReturnableBlockValues[expression]?.let {
return it.getFullExpression(coercion, cast)
}
return super.visitExpression(expression)
return expression
}
override fun visitReturn(expression: IrReturn): IrExpression {
@@ -3586,6 +3586,10 @@ task inline_coercionToUnit(type: KonanLocalTest) {
source = "codegen/inline/coercionToUnit.kt"
}
task inline_redundantCoercionsCleaner(type: KonanLocalTest) {
source = "codegen/inline/redundantCoercionsCleaner.kt"
}
task classDeclarationInsideInline(type: KonanLocalTest) {
source = "codegen/inline/classDeclarationInsideInline.kt"
goldValue = "test1: 1.0\n1\ntest2\n"
@@ -0,0 +1,17 @@
package codegen.inline.redundantCoercionsCleaner
import kotlin.test.*
inline fun runAndThrow(action: () -> Unit): Nothing {
action()
throw Exception()
}
inline fun foo(): Int = runAndThrow {
return 1
}
@Test fun runTest() {
val result: Any = foo()
assertEquals(1, result)
}