From 4d53d338e59beb240716508e0b6d32c182a17df6 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Wed, 27 Apr 2016 14:31:17 +0200 Subject: Fix error messages not being doubled and being on a new line --- .../tools/dotc/repl/CompilingInterpreter.scala | 38 ++++++++++++---------- src/dotty/tools/dotc/repl/Interpreter.scala | 2 +- src/dotty/tools/dotc/repl/InterpreterLoop.scala | 6 ++-- 3 files changed, 24 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala index d322aa404..b3b7ab13c 100644 --- a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala +++ b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala @@ -80,15 +80,13 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit 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 - } + var previousOutput: List[String] = Nil + + override def lastOutput() = { + val prev = previousOutput + previousOutput = Nil + prev + } override def delayOutputDuring[T](operation: => T): T = { val old = delayOutput @@ -113,14 +111,18 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit private def newReporter = new ConsoleReporter(Console.in, out) { override def printMessage(msg: String) = { - out.print(/*clean*/(msg) + "\n") - // Suppress clean for now for compiler messages - // Otherwise we will completely delete all references to - // line$object$ module classes. The previous interpreter did not - // have the project because the module class was written without the final `$' - // and therefore escaped the purge. We can turn this back on once - // we drop the final `$' from module classes. - out.flush() + if (!delayOutput) { + out.print(/*clean*/(msg) + "\n") + // Suppress clean for now for compiler messages + // Otherwise we will completely delete all references to + // line$object$ module classes. The previous interpreter did not + // have the project because the module class was written without the final `$' + // and therefore escaped the purge. We can turn this back on once + // we drop the final `$' from module classes. + out.flush() + } else { + previousOutput = (/*clean*/(msg) + "\n") :: previousOutput + } } } @@ -210,7 +212,7 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit else { val (interpreterResultString, succeeded) = req.loadAndRun() if (delayOutput) - previousOutput = clean(interpreterResultString) + previousOutput = clean(interpreterResultString) :: previousOutput else if (printResults || !succeeded) out.print(clean(interpreterResultString)) if (succeeded) { diff --git a/src/dotty/tools/dotc/repl/Interpreter.scala b/src/dotty/tools/dotc/repl/Interpreter.scala index 590baae0d..6a292dfe2 100644 --- a/src/dotty/tools/dotc/repl/Interpreter.scala +++ b/src/dotty/tools/dotc/repl/Interpreter.scala @@ -38,5 +38,5 @@ trait Interpreter { def delayOutputDuring[T](operation: => T): T /** Gets the last output not printed immediately */ - def lastOutput(): Option[String] + def lastOutput(): List[String] } diff --git a/src/dotty/tools/dotc/repl/InterpreterLoop.scala b/src/dotty/tools/dotc/repl/InterpreterLoop.scala index 98e47b635..c6c750b56 100644 --- a/src/dotty/tools/dotc/repl/InterpreterLoop.scala +++ b/src/dotty/tools/dotc/repl/InterpreterLoop.scala @@ -167,10 +167,10 @@ class InterpreterLoop(compiler: Compiler, config: REPL.Config)(implicit ctx: Con output.println("Unknown command. Type :help for help.") else shouldReplay = interpreter.lastOutput() match { // don't interpret twice - case Some(oldRes) => - output.print(oldRes) + case Nil => interpretStartingWith(line) + case oldRes => + oldRes foreach output.print Some(line) - case None => interpretStartingWith(line) } (true, shouldReplay) -- cgit v1.2.3