Properly handle REPL snippets with exceptions ...

so the REPL remain operational after exception in one of the snippets:
- separately return script class and script instance on evaluation (
  because in case of an exception the class is valid, while the instance
  is not).
- store both the class and the instance in the history
- handle this data accordingly
This commit is contained in:
Ilya Chernikov
2019-07-25 15:23:58 +02:00
parent 288fdc0952
commit ec3ccf1ba8
6 changed files with 52 additions and 26 deletions
@@ -41,11 +41,11 @@ open class BasicJvmScriptEvaluator : ScriptEvaluator {
compiledScript.resultField?.let { (resultFieldName, resultType) ->
val resultField = scriptClass.java.getDeclaredField(resultFieldName).apply { isAccessible = true }
ResultValue.Value(resultFieldName, resultField.get(instance), resultType.typeName, instance)
} ?: ResultValue.Unit(instance)
ResultValue.Value(resultFieldName, resultField.get(instance), resultType.typeName, scriptClass, instance)
} ?: ResultValue.Unit(scriptClass, instance)
} catch (e: InvocationTargetException) {
ResultValue.Error(e.targetException ?: e, e)
ResultValue.Error(e.targetException ?: e, e, scriptClass)
}
EvaluationResult(resultValue, refinedEvalConfiguration).let {