From d21a01ef599525bdb9fef91cde3f14db4d95dfc0 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 16 Nov 2020 14:42:50 +0100 Subject: [PATCH] IR: improve "no such .. argument slot" exception message Include the symbol signature, if it's available. --- .../ir/expressions/IrFunctionAccessExpression.kt | 4 ++-- .../kotlin/ir/expressions/IrMemberAccessExpression.kt | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrFunctionAccessExpression.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrFunctionAccessExpression.kt index 2151d2c0d7a..ac1c7d94245 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrFunctionAccessExpression.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrFunctionAccessExpression.kt @@ -21,14 +21,14 @@ abstract class IrFunctionAccessExpression( override fun getValueArgument(index: Int): IrExpression? { if (index >= valueArgumentsCount) { - throw AssertionError("$this: No such value argument slot: $index") + throwNoSuchArgumentSlotException("value", index, valueArgumentsCount) } return argumentsByParameterIndex[index] } override fun putValueArgument(index: Int, valueArgument: IrExpression?) { if (index >= valueArgumentsCount) { - throw AssertionError("$this: No such value argument slot: $index") + throwNoSuchArgumentSlotException("value", index, valueArgumentsCount) } argumentsByParameterIndex[index] = valueArgument } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrMemberAccessExpression.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrMemberAccessExpression.kt index 394038a7609..ce7396bdbc8 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrMemberAccessExpression.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrMemberAccessExpression.kt @@ -39,14 +39,14 @@ abstract class IrMemberAccessExpression(typeArgumentsCount: Int) : fun getTypeArgument(index: Int): IrType? { if (index >= typeArgumentsCount) { - throw AssertionError("$this: No such type argument slot: $index") + throwNoSuchArgumentSlotException("type", index, typeArgumentsCount) } return typeArgumentsByIndex[index] } fun putTypeArgument(index: Int, type: IrType?) { if (index >= typeArgumentsCount) { - throw AssertionError("$this: No such type argument slot: $index") + throwNoSuchArgumentSlotException("type", index, typeArgumentsCount) } typeArgumentsByIndex[index] = type } @@ -62,6 +62,13 @@ abstract class IrMemberAccessExpression(typeArgumentsCount: Int) : } } +internal fun IrMemberAccessExpression<*>.throwNoSuchArgumentSlotException(kind: String, index: Int, total: Int): Nothing { + throw AssertionError( + "No such $kind argument slot in ${this::class.java.simpleName}: $index (total=$total)" + + (symbol.signature?.let { ".\nSymbol: $it" } ?: "") + ) +} + fun IrMemberAccessExpression<*>.getTypeArgument(typeParameterDescriptor: TypeParameterDescriptor): IrType? = getTypeArgument(typeParameterDescriptor.index)