[IR] Made currentDeclarationParent nullable

This commit is contained in:
Igor Chevdar
2020-03-25 16:23:09 +03:00
parent 09304bbd54
commit 7a48c3a945
4 changed files with 5 additions and 5 deletions
@@ -99,7 +99,7 @@ abstract class IrElementTransformerVoidWithContext : IrElementTransformerVoid()
protected val currentScope get() = scopeStack.peek() protected val currentScope get() = scopeStack.peek()
protected val parentScope get() = if (scopeStack.size < 2) null else scopeStack[scopeStack.size - 2] protected val parentScope get() = if (scopeStack.size < 2) null else scopeStack[scopeStack.size - 2]
protected val allScopes get() = scopeStack 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() { fun printScopeStack() {
scopeStack.forEach { println(it.scope.scopeOwner) } scopeStack.forEach { println(it.scope.scopeOwner) }
@@ -118,7 +118,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
irBlock { irBlock {
+generateContinuationClassForLambda( +generateContinuationClassForLambda(
info, info,
currentDeclarationParent, currentDeclarationParent ?: error("No current declaration parent at ${expression.dump()}"),
(currentFunction?.irElement as? IrFunction)?.isInline == true (currentFunction?.irElement as? IrFunction)?.isInline == true
) )
val constructor = info.constructor val constructor = info.constructor
@@ -137,7 +137,7 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext)
origin = if (isLambda) JvmLoweredDeclarationOrigin.LAMBDA_IMPL else JvmLoweredDeclarationOrigin.FUNCTION_REFERENCE_IMPL origin = if (isLambda) JvmLoweredDeclarationOrigin.LAMBDA_IMPL else JvmLoweredDeclarationOrigin.FUNCTION_REFERENCE_IMPL
name = SpecialNames.NO_NAME_PROVIDED name = SpecialNames.NO_NAME_PROVIDED
}.apply { }.apply {
parent = currentDeclarationParent parent = currentDeclarationParent ?: error("No current declaration parent at ${irFunctionReference.dump()}")
superTypes += superType superTypes += superType
if (samSuperType == null) if (samSuperType == null)
superTypes += functionSuperClass.typeWith(parameterTypes) superTypes += functionSuperClass.typeWith(parameterTypes)
@@ -83,7 +83,7 @@ internal class InlineCallableReferenceToLambdaPhase(val context: JvmBackendConte
returnType = field.type returnType = field.type
isSuspend = false isSuspend = false
}.apply { }.apply {
parent = currentDeclarationParent parent = currentDeclarationParent ?: error("No current declaration parent at ${expression.dump()}")
val boundReceiver = expression.dispatchReceiver ?: expression.extensionReceiver val boundReceiver = expression.dispatchReceiver ?: expression.extensionReceiver
val receiver = val receiver =
@@ -140,7 +140,7 @@ internal class InlineCallableReferenceToLambdaPhase(val context: JvmBackendConte
returnType = referencedFunction.returnType returnType = referencedFunction.returnType
isSuspend = referencedFunction.isSuspend isSuspend = referencedFunction.isSuspend
}.apply { }.apply {
parent = currentDeclarationParent parent = currentDeclarationParent!!
for ((index, argumentType) in argumentTypes.withIndex()) { for ((index, argumentType) in argumentTypes.withIndex()) {
addValueParameter { addValueParameter {
name = Name.identifier("p$index") name = Name.identifier("p$index")