Native: RedundantCoercionsCleaner should rewrite nested returns too
This commit is contained in:
committed by
Space
parent
3176dd1341
commit
981a6ffeb8
+2
-1
@@ -163,10 +163,11 @@ internal class RedundantCoercionsCleaner(val context: Context) : FileLoweringPas
|
|||||||
}
|
}
|
||||||
transformedReturnableBlock.transformChildrenVoid(object: IrElementTransformerVoid() {
|
transformedReturnableBlock.transformChildrenVoid(object: IrElementTransformerVoid() {
|
||||||
override fun visitExpression(expression: IrExpression): IrExpression {
|
override fun visitExpression(expression: IrExpression): IrExpression {
|
||||||
|
expression.transformChildrenVoid()
|
||||||
foldedReturnableBlockValues[expression]?.let {
|
foldedReturnableBlockValues[expression]?.let {
|
||||||
return it.getFullExpression(coercion, cast)
|
return it.getFullExpression(coercion, cast)
|
||||||
}
|
}
|
||||||
return super.visitExpression(expression)
|
return expression
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitReturn(expression: IrReturn): IrExpression {
|
override fun visitReturn(expression: IrReturn): IrExpression {
|
||||||
|
|||||||
@@ -3586,6 +3586,10 @@ task inline_coercionToUnit(type: KonanLocalTest) {
|
|||||||
source = "codegen/inline/coercionToUnit.kt"
|
source = "codegen/inline/coercionToUnit.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task inline_redundantCoercionsCleaner(type: KonanLocalTest) {
|
||||||
|
source = "codegen/inline/redundantCoercionsCleaner.kt"
|
||||||
|
}
|
||||||
|
|
||||||
task classDeclarationInsideInline(type: KonanLocalTest) {
|
task classDeclarationInsideInline(type: KonanLocalTest) {
|
||||||
source = "codegen/inline/classDeclarationInsideInline.kt"
|
source = "codegen/inline/classDeclarationInsideInline.kt"
|
||||||
goldValue = "test1: 1.0\n1\ntest2\n"
|
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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user