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
@@ -80,9 +80,11 @@ class ReplTest : TestCase() {
simpleScriptompilationConfiguration,
simpleScriptEvaluationConfiguration,
sequenceOf(
"throw RuntimeException(\"abc\")"
"throw RuntimeException(\"abc\")",
"val x = 3",
"x + 1"
),
sequenceOf(RuntimeException("abc"))
sequenceOf(RuntimeException("abc"), null, 4)
)
}
@@ -107,11 +109,12 @@ class ReplTest : TestCase() {
}
}
.onSuccess {
it.returnValue.scriptInstance?.let { snippetInstance ->
currentEvalConfig = ScriptEvaluationConfiguration(currentEvalConfig) {
previousSnippets.append(snippetInstance)
val snippetClass = it.returnValue.scriptClass
currentEvalConfig = ScriptEvaluationConfiguration(currentEvalConfig) {
previousSnippets.append(it.returnValue.scriptInstance)
if (snippetClass != null) {
jvm {
baseClassLoader(snippetInstance::class.java.classLoader)
baseClassLoader(snippetClass.java.classLoader)
}
}
}