From 57670a38ca55cc04c9d765bdf04584cad5581d41 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Wed, 27 Apr 2016 13:38:38 +0200 Subject: Stop interpreter from interpreting twice on enter --- .../tools/dotc/repl/CompilingInterpreter.scala | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/dotty/tools/dotc/repl/CompilingInterpreter.scala') diff --git a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala index cfcce106e..d322aa404 100644 --- a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala +++ b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala @@ -78,6 +78,27 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit /** whether to print out result lines */ private var printResults: Boolean = true + private var delayOutput: Boolean = false + + var previousOutput: String = null + + override def lastOutput() = + if (previousOutput == null) None + else { + val ret = Some(previousOutput) + previousOutput = null + ret + } + + override def delayOutputDuring[T](operation: => T): T = { + val old = delayOutput + try { + delayOutput = true + operation + } finally { + delayOutput = old + } + } /** Temporarily be quiet */ override def beQuietDuring[T](operation: => T): T = { @@ -188,7 +209,9 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit Interpreter.Error // an error happened during compilation, e.g. a type error else { val (interpreterResultString, succeeded) = req.loadAndRun() - if (printResults || !succeeded) + if (delayOutput) + previousOutput = clean(interpreterResultString) + else if (printResults || !succeeded) out.print(clean(interpreterResultString)) if (succeeded) { prevRequests += req -- cgit v1.2.3