Drop redundant frames after some of exceptions in interpreter

Drop only last frame because it is pointing on function itself.
This commit is contained in:
Ivan Kylchik
2021-06-24 15:03:07 +03:00
committed by TeamCityServer
parent 334d518aba
commit a9abf3b9b6
4 changed files with 5 additions and 4 deletions
@@ -77,8 +77,10 @@ internal fun unfoldInstruction(element: IrElement?, environment: IrInterpreterEn
}
private fun unfoldFunction(function: IrSimpleFunction, environment: IrInterpreterEnvironment) {
if (environment.callStack.getStackCount() >= environment.configuration.maxStack)
if (environment.callStack.getStackCount() >= environment.configuration.maxStack) {
environment.callStack.dropFrame() // current frame is pointing on function and is redundant
return StackOverflowError().handleUserException(environment)
}
// SimpleInstruction with function is added in IrCall
// It will serve as endpoint for all possible calls, there we drop frame and copy result to new one
function.body?.let { environment.callStack.addInstruction(CompoundInstruction(it)) }
@@ -180,6 +180,7 @@ internal fun IrFunction?.checkCast(environment: IrInterpreterEnvironment): Boole
if (!actualState.isSubtypeOf(expectedType)) {
val convertibleClassName = environment.callStack.popState().irClass.fqNameWhenAvailable
environment.callStack.dropFrame() // current frame is pointing on function and is redundant
ClassCastException("$convertibleClassName cannot be cast to ${expectedType.render()}").handleUserException(environment)
return false
}