Skip to content

Fix and reinstate repl/errmsgs #13459

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 3 commits into from
Sep 4, 2021
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
41 changes: 22 additions & 19 deletions compiler/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@ import Diagnostic.{ Error, ConditionalWarning }
class ConsoleReporter(
reader: BufferedReader = Console.in,
writer: PrintWriter = new PrintWriter(Console.err, true)
) extends AbstractReporter {
) extends ConsoleReporter.AbstractConsoleReporter {
override def printMessage(msg: String): Unit = { writer.print(msg + "\n"); writer.flush() }
override def flush()(using Context): Unit = writer.flush()

import Diagnostic._

/** Prints the message. */
def printMessage(msg: String): Unit = { writer.print(msg + "\n"); writer.flush() }

/** Prints the message with the given position indication. */
def doReport(dia: Diagnostic)(using Context): Unit = {
override def doReport(dia: Diagnostic)(using Context): Unit = {
super.doReport(dia)
dia match
case dia: Error =>
printMessage(messageAndPos(dia))
if (ctx.settings.Xprompt.value) Reporter.displayPrompt(reader, writer)
case dia =>
printMessage(messageAndPos(dia))

if shouldExplain(dia) then
printMessage(explanation(dia.msg))
else if dia.msg.canExplain then
printMessage("\nlonger explanation available when compiling with `-explain`")
case dia: Error if ctx.settings.Xprompt.value => Reporter.displayPrompt(reader, writer)
case _ =>
}
}

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

override def flush()(using Context): Unit = { writer.flush() }
/** Prints the message with the given position indication. */
def doReport(dia: Diagnostic)(using Context): Unit = {
printMessage(messageAndPos(dia))
if Diagnostic.shouldExplain(dia) then
printMessage(explanation(dia.msg))
else if dia.msg.canExplain then
printMessage("\nlonger explanation available when compiling with `-explain`")
}
}
}
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dotty.tools.repl

import java.io.{File => JFile, PrintStream, PrintWriter}
import java.io.{File => JFile, PrintStream}
import java.nio.charset.StandardCharsets

import dotty.tools.dotc.ast.Trees._
Expand Down Expand Up @@ -425,12 +425,12 @@ class ReplDriver(settings: Array[String],
state
}

/** Like ConsoleReporter, but without file paths or real -Xprompt'ing */
private object ReplConsoleReporter extends ConsoleReporter(
reader = null, // this short-circuits the -Xprompt display from waiting for an input
writer = new PrintWriter(out, /* autoFlush = */ true), // write to out, not Console.err
) {
/** Like ConsoleReporter, but without file paths, -Xprompt displaying,
* and using a PrintStream rather than a PrintWriter so messages aren't re-encoded. */
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 flush()(using Context): Unit = out.flush()
}

/** Print warnings & errors using ReplConsoleReporter, and info straight to out */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ scala> abstract class C { type T; val x: T; val s: Unit = { type T = String; var
1 | abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
| ^
|Found: (C.this.x : C.this.T)
|Required: T?
|Required: T²
|
|where: T is a type in class C
| T? is a type in the initializer of value s which is an alias of String
| T² is a type in the initializer of value s which is an alias of String
longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
| ^
|Found: (y : T)
|Required: T?
|Required: T²
|
|where: T is a type in the initializer of value s which is an alias of String
| T? is a type in method f which is an alias of Int
| T² is a type in method f which is an alias of Int
longer explanation available when compiling with `-explain`
2 errors found
scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
Expand Down