Skip to content

Commit 4d53d33

Browse files
committed
Fix error messages not being doubled and being on a new line
1 parent d1ec140 commit 4d53d33

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

src/dotty/tools/dotc/repl/CompilingInterpreter.scala

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,13 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit
8080
private var printResults: Boolean = true
8181
private var delayOutput: Boolean = false
8282

83-
var previousOutput: String = null
84-
85-
override def lastOutput() =
86-
if (previousOutput == null) None
87-
else {
88-
val ret = Some(previousOutput)
89-
previousOutput = null
90-
ret
91-
}
83+
var previousOutput: List[String] = Nil
84+
85+
override def lastOutput() = {
86+
val prev = previousOutput
87+
previousOutput = Nil
88+
prev
89+
}
9290

9391
override def delayOutputDuring[T](operation: => T): T = {
9492
val old = delayOutput
@@ -113,14 +111,18 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit
113111

114112
private def newReporter = new ConsoleReporter(Console.in, out) {
115113
override def printMessage(msg: String) = {
116-
out.print(/*clean*/(msg) + "\n")
117-
// Suppress clean for now for compiler messages
118-
// Otherwise we will completely delete all references to
119-
// line$object$ module classes. The previous interpreter did not
120-
// have the project because the module class was written without the final `$'
121-
// and therefore escaped the purge. We can turn this back on once
122-
// we drop the final `$' from module classes.
123-
out.flush()
114+
if (!delayOutput) {
115+
out.print(/*clean*/(msg) + "\n")
116+
// Suppress clean for now for compiler messages
117+
// Otherwise we will completely delete all references to
118+
// line$object$ module classes. The previous interpreter did not
119+
// have the project because the module class was written without the final `$'
120+
// and therefore escaped the purge. We can turn this back on once
121+
// we drop the final `$' from module classes.
122+
out.flush()
123+
} else {
124+
previousOutput = (/*clean*/(msg) + "\n") :: previousOutput
125+
}
124126
}
125127
}
126128

@@ -210,7 +212,7 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit
210212
else {
211213
val (interpreterResultString, succeeded) = req.loadAndRun()
212214
if (delayOutput)
213-
previousOutput = clean(interpreterResultString)
215+
previousOutput = clean(interpreterResultString) :: previousOutput
214216
else if (printResults || !succeeded)
215217
out.print(clean(interpreterResultString))
216218
if (succeeded) {

src/dotty/tools/dotc/repl/Interpreter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ trait Interpreter {
3838
def delayOutputDuring[T](operation: => T): T
3939

4040
/** Gets the last output not printed immediately */
41-
def lastOutput(): Option[String]
41+
def lastOutput(): List[String]
4242
}

src/dotty/tools/dotc/repl/InterpreterLoop.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ class InterpreterLoop(compiler: Compiler, config: REPL.Config)(implicit ctx: Con
167167
output.println("Unknown command. Type :help for help.")
168168
else
169169
shouldReplay = interpreter.lastOutput() match { // don't interpret twice
170-
case Some(oldRes) =>
171-
output.print(oldRes)
170+
case Nil => interpretStartingWith(line)
171+
case oldRes =>
172+
oldRes foreach output.print
172173
Some(line)
173-
case None => interpretStartingWith(line)
174174
}
175175

176176
(true, shouldReplay)

0 commit comments

Comments
 (0)