Skip to content

ConsoleReporter sends INFO to stdout #20328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions compiler/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ package reporting
import core.Contexts.*
import java.io.{ BufferedReader, PrintWriter }
import Diagnostic.*
import dotty.tools.dotc.interfaces.Diagnostic.INFO

/**
* This class implements a Reporter that displays messages on a text console
*/
class ConsoleReporter(
reader: BufferedReader = Console.in,
writer: PrintWriter = new PrintWriter(Console.err, true)
writer: PrintWriter = new PrintWriter(Console.err, true),
echoer: PrintWriter = new PrintWriter(Console.out, true)
) extends ConsoleReporter.AbstractConsoleReporter {
override def printMessage(msg: String): Unit = { writer.print(msg + "\n"); writer.flush() }
override def printMessage(msg: String): Unit = { writer.println(msg); writer.flush() }
override def echoMessage(msg: String): Unit = { echoer.println(msg); echoer.flush() }
override def flush()(using Context): Unit = writer.flush()

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

object ConsoleReporter {
abstract class AbstractConsoleReporter extends AbstractReporter {
/** Prints the message. */
/** Print the diagnostic message. */
def printMessage(msg: String): Unit

/** Prints the message with the given position indication. */
def doReport(dia: Diagnostic)(using Context): Unit = {
printMessage(messageAndPos(dia))
}
/** Print the informative message. */
def echoMessage(msg: String): Unit

/** Print the message with the given position indication. */
def doReport(dia: Diagnostic)(using Context): Unit =
if dia.level == INFO then echoMessage(messageAndPos(dia))
else printMessage(messageAndPos(dia))
}
}
7 changes: 3 additions & 4 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import dotty.tools.dotc.util.NoSourcePosition
import java.io.{BufferedReader, PrintWriter}
import scala.annotation.internal.sharable
import scala.collection.mutable
import core.Decorators.em
import core.Decorators.{em, toMessage}
import core.handleRecursive

object Reporter {
Expand Down Expand Up @@ -236,10 +236,9 @@ abstract class Reporter extends interfaces.ReporterResult {
report(Warning(msg, NoSourcePosition))

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

/** Returns a string meaning "n elements". */
protected def countString(n: Int, elements: String): String = n match {
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ class ReplDriver(settings: Array[String],
private object ReplConsoleReporter extends ConsoleReporter.AbstractConsoleReporter {
override def posFileStr(pos: SourcePosition) = "" // omit file paths
override def printMessage(msg: String): Unit = out.println(msg)
override def echoMessage(msg: String): Unit = printMessage(msg)
override def flush()(using Context): Unit = out.flush()
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/test/dotty/tools/dotc/reporting/TestReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
_diagnosticBuf.append(dia)
printMessageAndPos(dia, extra)
}

override def printSummary()(using Context): Unit = ()
}

object TestReporter {
Expand Down
Loading