Skip to content

Commit 528753d

Browse files
committed
ConsoleReporter sends INFO to stdout
1 parent 05354ba commit 528753d

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

compiler/src/dotty/tools/dotc/reporting/ConsoleReporter.scala

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ package reporting
55
import core.Contexts.*
66
import java.io.{ BufferedReader, PrintWriter }
77
import Diagnostic.*
8+
import dotty.tools.dotc.interfaces.Diagnostic.INFO
89

910
/**
1011
* This class implements a Reporter that displays messages on a text console
1112
*/
1213
class ConsoleReporter(
1314
reader: BufferedReader = Console.in,
14-
writer: PrintWriter = new PrintWriter(Console.err, true)
15+
writer: PrintWriter = new PrintWriter(Console.err, true),
16+
echoer: PrintWriter = new PrintWriter(Console.out, true)
1517
) extends ConsoleReporter.AbstractConsoleReporter {
16-
override def printMessage(msg: String): Unit = { writer.print(msg + "\n"); writer.flush() }
18+
override def printMessage(msg: String): Unit = { writer.println(msg); writer.flush() }
19+
override def echoMessage(msg: String): Unit = { echoer.println(msg); echoer.flush() }
1720
override def flush()(using Context): Unit = writer.flush()
1821

1922
override def doReport(dia: Diagnostic)(using Context): Unit = {
@@ -22,18 +25,21 @@ class ConsoleReporter(
2225
dia match
2326
case _: Error => Reporter.displayPrompt(reader, writer)
2427
case _: Warning if ctx.settings.XfatalWarnings.value => Reporter.displayPrompt(reader, writer)
25-
case _ =>
28+
case _ =>
2629
}
2730
}
2831

2932
object ConsoleReporter {
3033
abstract class AbstractConsoleReporter extends AbstractReporter {
31-
/** Prints the message. */
34+
/** Print the diagnostic message. */
3235
def printMessage(msg: String): Unit
3336

34-
/** Prints the message with the given position indication. */
35-
def doReport(dia: Diagnostic)(using Context): Unit = {
36-
printMessage(messageAndPos(dia))
37-
}
37+
/** Print the informative message. */
38+
def echoMessage(msg: String): Unit
39+
40+
/** Print the message with the given position indication. */
41+
def doReport(dia: Diagnostic)(using Context): Unit =
42+
if dia.level == INFO then echoMessage(messageAndPos(dia))
43+
else printMessage(messageAndPos(dia))
3844
}
3945
}

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import dotty.tools.dotc.util.NoSourcePosition
1414
import java.io.{BufferedReader, PrintWriter}
1515
import scala.annotation.internal.sharable
1616
import scala.collection.mutable
17-
import core.Decorators.em
17+
import core.Decorators.{em, toMessage}
1818
import core.handleRecursive
1919

2020
object Reporter {
@@ -233,13 +233,12 @@ abstract class Reporter extends interfaces.ReporterResult {
233233
for (settingName, count) <- unreportedWarnings do
234234
val were = if count == 1 then "was" else "were"
235235
val msg = em"there $were ${countString(count, settingName.tail + " warning")}; re-run with $settingName for details"
236-
report(Warning(msg, NoSourcePosition))
236+
doReport(Warning(msg, NoSourcePosition))
237237

238238
/** Print the summary of warnings and errors */
239-
def printSummary()(using Context): Unit = {
239+
def printSummary()(using Context): Unit =
240240
val s = summary
241-
if (s != "") report(new Info(s, NoSourcePosition))
242-
}
241+
if (s != "") doReport(Warning(s.toMessage, NoSourcePosition))
243242

244243
/** Returns a string meaning "n elements". */
245244
protected def countString(n: Int, elements: String): String = n match {

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ class ReplDriver(settings: Array[String],
545545
private object ReplConsoleReporter extends ConsoleReporter.AbstractConsoleReporter {
546546
override def posFileStr(pos: SourcePosition) = "" // omit file paths
547547
override def printMessage(msg: String): Unit = out.println(msg)
548+
override def echoMessage(msg: String): Unit = printMessage(msg)
548549
override def flush()(using Context): Unit = out.flush()
549550
}
550551

0 commit comments

Comments
 (0)