Increment repl line generation on compilation error
fixes #KT-17921 and #KT-21141 Tests added to the JSR223 local eval example
This commit is contained in:
@@ -53,6 +53,7 @@ open class BasicReplStageHistory<T>(override val lock: ReentrantReadWriteLock =
|
||||
lock.write {
|
||||
val removed = map { it.id }
|
||||
clear()
|
||||
currentGeneration.incrementAndGet()
|
||||
return removed
|
||||
}
|
||||
}
|
||||
@@ -67,7 +68,10 @@ open class BasicReplStageHistory<T>(override val lock: ReentrantReadWriteLock =
|
||||
currentGeneration.incrementAndGet()
|
||||
removed
|
||||
}
|
||||
else emptyList()
|
||||
else {
|
||||
currentGeneration.incrementAndGet()
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
-9
@@ -35,7 +35,15 @@ class GenericReplCompilingEvaluator(val compiler: ReplCompiler,
|
||||
val aggregatedState = state.asState(AggregatedReplStageState::class.java)
|
||||
val compiled = compiler.compile(state, codeLine)
|
||||
when (compiled) {
|
||||
is ReplCompileResult.Error -> ReplEvalResult.Error.CompileTime(compiled.message, compiled.location)
|
||||
is ReplCompileResult.Error -> {
|
||||
aggregatedState.apply {
|
||||
lock.write {
|
||||
assert(state1.history.size == state2.history.size)
|
||||
adjustHistories() // needed due to statefulness of AnalyzerEngine - in case of compilation errors the line name reuse leads to #KT-17921
|
||||
}
|
||||
}
|
||||
ReplEvalResult.Error.CompileTime(compiled.message, compiled.location)
|
||||
}
|
||||
is ReplCompileResult.Incomplete -> ReplEvalResult.Incomplete()
|
||||
is ReplCompileResult.CompiledClasses -> {
|
||||
val result = eval(state, compiled, scriptArgs, invokeWrapper)
|
||||
@@ -46,14 +54,7 @@ class GenericReplCompilingEvaluator(val compiler: ReplCompiler,
|
||||
aggregatedState.apply {
|
||||
lock.write {
|
||||
if (state1.history.size > state2.history.size) {
|
||||
if (state2.history.size == 0) {
|
||||
state1.history.reset()
|
||||
}
|
||||
else {
|
||||
state2.history.peek()?.let {
|
||||
state1.history.resetTo(it.id)
|
||||
}
|
||||
}
|
||||
adjustHistories()
|
||||
assert(state1.history.size == state2.history.size)
|
||||
}
|
||||
}
|
||||
@@ -91,3 +92,9 @@ class GenericReplCompilingEvaluator(val compiler: ReplCompiler,
|
||||
evaluator.eval(state, compiledCode, scriptArgs ?: defaultScriptArgs, invokeWrapper)
|
||||
}
|
||||
}
|
||||
|
||||
private fun AggregatedReplStageState<*, *>.adjustHistories(): Iterable<ILineId>? =
|
||||
state2.history.peek()?.let {
|
||||
state1.history.resetTo(it.id)
|
||||
}
|
||||
?: state1.history.reset()
|
||||
|
||||
Reference in New Issue
Block a user