From 7a48c3a945615040128caa13d68f2d349d0b5e56 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Wed, 25 Mar 2020 16:23:09 +0300 Subject: [PATCH] [IR] Made currentDeclarationParent nullable --- .../backend/common/IrElementTransformerVoidWithContext.kt | 2 +- .../kotlin/backend/jvm/lower/AddContinuationLowering.kt | 2 +- .../kotlin/backend/jvm/lower/CallableReferenceLowering.kt | 2 +- .../backend/jvm/lower/InlineCallableReferenceToLambda.kt | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/IrElementTransformerVoidWithContext.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/IrElementTransformerVoidWithContext.kt index 8996c8668ec..9d5665f0007 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/IrElementTransformerVoidWithContext.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/IrElementTransformerVoidWithContext.kt @@ -99,7 +99,7 @@ abstract class IrElementTransformerVoidWithContext : IrElementTransformerVoid() protected val currentScope get() = scopeStack.peek() protected val parentScope get() = if (scopeStack.size < 2) null else scopeStack[scopeStack.size - 2] protected val allScopes get() = scopeStack - protected val currentDeclarationParent get() = allScopes.last { it.irElement is IrDeclarationParent }.irElement as IrDeclarationParent + protected val currentDeclarationParent get() = scopeStack.lastOrNull { it.irElement is IrDeclarationParent }?.irElement as? IrDeclarationParent fun printScopeStack() { scopeStack.forEach { println(it.scope.scopeOwner) } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt index 90c813fe87b..a6f81e2def9 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt @@ -118,7 +118,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : irBlock { +generateContinuationClassForLambda( info, - currentDeclarationParent, + currentDeclarationParent ?: error("No current declaration parent at ${expression.dump()}"), (currentFunction?.irElement as? IrFunction)?.isInline == true ) val constructor = info.constructor diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt index ffd58ad3005..fca3af90edb 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt @@ -137,7 +137,7 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext) origin = if (isLambda) JvmLoweredDeclarationOrigin.LAMBDA_IMPL else JvmLoweredDeclarationOrigin.FUNCTION_REFERENCE_IMPL name = SpecialNames.NO_NAME_PROVIDED }.apply { - parent = currentDeclarationParent + parent = currentDeclarationParent ?: error("No current declaration parent at ${irFunctionReference.dump()}") superTypes += superType if (samSuperType == null) superTypes += functionSuperClass.typeWith(parameterTypes) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt index 64f1ad2ebe8..408d5153eb9 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt @@ -83,7 +83,7 @@ internal class InlineCallableReferenceToLambdaPhase(val context: JvmBackendConte returnType = field.type isSuspend = false }.apply { - parent = currentDeclarationParent + parent = currentDeclarationParent ?: error("No current declaration parent at ${expression.dump()}") val boundReceiver = expression.dispatchReceiver ?: expression.extensionReceiver val receiver = @@ -140,7 +140,7 @@ internal class InlineCallableReferenceToLambdaPhase(val context: JvmBackendConte returnType = referencedFunction.returnType isSuspend = referencedFunction.isSuspend }.apply { - parent = currentDeclarationParent + parent = currentDeclarationParent!! for ((index, argumentType) in argumentTypes.withIndex()) { addValueParameter { name = Name.identifier("p$index")