Throw detailed exceptions for incorrect argument indices

This commit is contained in:
Dmitry Petrov
2018-03-27 10:51:51 +03:00
parent 9a76ee63ab
commit 47b3152bd0
3 changed files with 18 additions and 9 deletions
@@ -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<IrExpression?> = 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
}
@@ -38,10 +38,17 @@ abstract class IrMemberAccessExpressionBase(
private val typeArgumentsByIndex = arrayOfNulls<KotlinType>(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
}
@@ -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