IR: improve "no such .. argument slot" exception message

Include the symbol signature, if it's available.
This commit is contained in:
Alexander Udalov
2020-11-16 14:42:50 +01:00
parent 8ede19811d
commit d21a01ef59
2 changed files with 11 additions and 4 deletions
@@ -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
}
@@ -39,14 +39,14 @@ abstract class IrMemberAccessExpression<S : IrSymbol>(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<S : IrSymbol>(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)