From 47b3152bd0b729f28971b3181e73b6aa66a34777 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 27 Mar 2018 10:51:51 +0300 Subject: [PATCH] Throw detailed exceptions for incorrect argument indices --- .../impl/IrCallWithIndexedArgumentsBase.kt | 9 ++++----- .../expressions/impl/IrMemberAccessExpressionBase.kt | 11 +++++++++-- .../kotlin/ir/expressions/impl/IrPrimitiveCall.kt | 7 +++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallWithIndexedArgumentsBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallWithIndexedArgumentsBase.kt index 0cb660a9e17..11923ae71d4 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallWithIndexedArgumentsBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallWithIndexedArgumentsBase.kt @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.ir.util.render import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.types.KotlinType -import java.lang.AssertionError abstract class IrCallWithIndexedArgumentsBase( startOffset: Int, @@ -36,15 +35,15 @@ abstract class IrCallWithIndexedArgumentsBase( private val argumentsByParameterIndex: Array = arrayOfNulls(valueArgumentsCount) override fun getValueArgument(index: Int): IrExpression? { - if (index >= argumentsByParameterIndex.size) { - throw AssertionError("$this: No such argument slot: $index in ${render()}") + if (index >= valueArgumentsCount) { + throw AssertionError("$this: No such value argument slot: $index") } return argumentsByParameterIndex[index] } override fun putValueArgument(index: Int, valueArgument: IrExpression?) { - if (index >= argumentsByParameterIndex.size) { - throw AssertionError("$this: No such argument slot: $index in ${render()}") + if (index >= valueArgumentsCount) { + throw AssertionError("$this: No such value argument slot: $index") } argumentsByParameterIndex[index] = valueArgument } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrMemberAccessExpressionBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrMemberAccessExpressionBase.kt index 7605bd8ecae..ba1cc31216c 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrMemberAccessExpressionBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrMemberAccessExpressionBase.kt @@ -38,10 +38,17 @@ abstract class IrMemberAccessExpressionBase( private val typeArgumentsByIndex = arrayOfNulls(typeArgumentsCount) - override fun getTypeArgument(index: Int): KotlinType? = - typeArgumentsByIndex[index] + override fun getTypeArgument(index: Int): KotlinType? { + if (index >= typeArgumentsCount) { + throw AssertionError("$this: No such type argument slot: $index") + } + return typeArgumentsByIndex[index] + } override fun putTypeArgument(index: Int, type: KotlinType?) { + if (index >= typeArgumentsCount) { + throw AssertionError("$this: No such type argument slot: $index") + } typeArgumentsByIndex[index] = type } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPrimitiveCall.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPrimitiveCall.kt index 3ccd6e90b10..3ae80f410b7 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPrimitiveCall.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPrimitiveCall.kt @@ -45,9 +45,12 @@ abstract class IrPrimitiveCallBase( override val typeArgumentsCount: Int = 0 - override fun getTypeArgument(index: Int): KotlinType? = null + override fun getTypeArgument(index: Int): KotlinType? = + throw AssertionError("Primitive $descriptor has no type arguments") - override fun putTypeArgument(index: Int, type: KotlinType?) {} + override fun putTypeArgument(index: Int, type: KotlinType?) { + throw AssertionError("Primitive $descriptor has no type arguments") + } override var dispatchReceiver: IrExpression? get() = null