IR: check whether local declarations need to throw after Nothing return
^KT-48982 Fixed
This commit is contained in:
+7
@@ -7,8 +7,10 @@ package org.jetbrains.kotlin.backend.common.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
|
||||
import org.jetbrains.kotlin.ir.builders.irCall
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
@@ -20,6 +22,9 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
class KotlinNothingValueExceptionLowering(
|
||||
val backendContext: CommonBackendContext, val skip: (IrDeclaration) -> Boolean = { false }
|
||||
) : BodyLoweringPass {
|
||||
override fun lower(irFile: IrFile) =
|
||||
runOnFilePostfix(irFile, withLocalDeclarations = true)
|
||||
|
||||
override fun lower(irBody: IrBody, container: IrDeclaration) {
|
||||
if (!skip(container)) {
|
||||
irBody.transformChildrenVoid(Transformer(container.symbol))
|
||||
@@ -27,6 +32,8 @@ class KotlinNothingValueExceptionLowering(
|
||||
}
|
||||
|
||||
private inner class Transformer(val parent: IrSymbol) : IrElementTransformerVoid() {
|
||||
override fun visitBody(body: IrBody): IrBody = body
|
||||
|
||||
override fun visitCall(expression: IrCall): IrExpression =
|
||||
if (expression.type.isNothing()) {
|
||||
// Replace call 'foo' of type 'kotlin.Nothing' with a block:
|
||||
|
||||
Reference in New Issue
Block a user