diff options
-rw-r--r-- | src/dotty/tools/dotc/Compiler.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/Driver.scala | 6 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/Highlighting.scala | 70 | ||||
-rw-r--r-- | src/dotty/tools/dotc/reporting/ConsoleReporter.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/ErrorReporting.scala | 6 | ||||
-rw-r--r-- | test/dotc/tests.scala | 3 | ||||
-rw-r--r-- | test/test/CompilerTest.scala | 11 | ||||
-rw-r--r-- | test/test/OtherEntryPointsTest.scala | 3 | ||||
-rw-r--r-- | tests/repl/errmsgs.check | 48 | ||||
-rw-r--r-- | tests/repl/imports.check | 12 |
11 files changed, 89 insertions, 78 deletions
diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index d6e3cc89b..ea6254f5b 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -140,10 +140,6 @@ class Compiler { .setTyper(new Typer) .setMode(Mode.ImplicitsEnabled) .setTyperState(new MutableTyperState(ctx.typerState, ctx.typerState.reporter, isCommittable = true)) - .setReporter( - if (ctx.settings.color.value == "never") new ConsoleReporter() - else new FancyConsoleReporter() - ) ctx.initialize()(start) // re-initialize the base context with start def addImport(ctx: Context, refFn: () => TermRef) = ctx.fresh.setImportInfo(ImportInfo.rootImport(refFn)(ctx)) diff --git a/src/dotty/tools/dotc/Driver.scala b/src/dotty/tools/dotc/Driver.scala index f54a23ad2..b2dc18d2a 100644 --- a/src/dotty/tools/dotc/Driver.scala +++ b/src/dotty/tools/dotc/Driver.scala @@ -22,7 +22,11 @@ abstract class Driver extends DotClass { protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter = if (fileNames.nonEmpty) try { - val run = compiler.newRun + val fresh = ctx.fresh.setReporter { + if (ctx.settings.color.value == "never") new ConsoleReporter() + else new FancyConsoleReporter() + } + val run = compiler.newRun(fresh) run.compile(fileNames) run.printSummary() } diff --git a/src/dotty/tools/dotc/printing/Highlighting.scala b/src/dotty/tools/dotc/printing/Highlighting.scala index a496976a1..75f83bf29 100644 --- a/src/dotty/tools/dotc/printing/Highlighting.scala +++ b/src/dotty/tools/dotc/printing/Highlighting.scala @@ -6,33 +6,38 @@ import scala.collection.mutable object Highlighting { - implicit def colorToString(c: Color): String = c.toString - implicit def cbufToString(cb: ColorBuffer): String = cb.toString + implicit def highlightToString(h: Highlight): String = h.toString + implicit def hbufToString(hb: HighlightBuffer): String = hb.toString - abstract class Color(private val color: String) { + abstract class Highlight(private val highlight: String) { def text: String - override def toString = color + text + Console.RESET + override def toString = highlight + text + Console.RESET - def +(other: Color): ColorBuffer = - new ColorBuffer(this) + other + def +(other: Highlight): HighlightBuffer = + new HighlightBuffer(this) + other - def +(other: String): ColorBuffer = - new ColorBuffer(this) + other + def +(other: String): HighlightBuffer = + new HighlightBuffer(this) + other } - case class ColorBuffer(color: Color) { + abstract class Modifier(private val mod: String, text: String) extends Highlight(Console.RESET) { + override def toString = + mod + super.toString + } + + case class HighlightBuffer(hl: Highlight) { val buffer = new mutable.ListBuffer[String] - buffer += color.toString + buffer += hl.toString - def +(color: Color): ColorBuffer = { - buffer += color.toString + def +(other: Highlight): HighlightBuffer = { + buffer += other.toString this } - def +(str: String): ColorBuffer = { - buffer += str + def +(other: String): HighlightBuffer = { + buffer += other this } @@ -40,21 +45,24 @@ object Highlighting { buffer.mkString } - case class Red(text: String) extends Color(Console.RED) - case class Blue(text: String) extends Color(Console.BLUE) - case class Cyan(text: String) extends Color(Console.CYAN) - case class Black(text: String) extends Color(Console.BLACK) - case class Green(text: String) extends Color(Console.GREEN) - case class White(text: String) extends Color(Console.WHITE) - case class Yellow(text: String) extends Color(Console.YELLOW) - case class Magenta(text: String) extends Color(Console.MAGENTA) - - case class RedB(text: String) extends Color(Console.RED_B) - case class BlueB(text: String) extends Color(Console.BLUE_B) - case class CyanB(text: String) extends Color(Console.CYAN_B) - case class BlackB(text: String) extends Color(Console.BLACK_B) - case class GreenB(text: String) extends Color(Console.GREEN_B) - case class WhiteB(text: String) extends Color(Console.WHITE_B) - case class YellowB(text: String) extends Color(Console.YELLOW_B) - case class MagentaB(text: String) extends Color(Console.MAGENTA_B) + case class Red(text: String) extends Highlight(Console.RED) + case class Blue(text: String) extends Highlight(Console.BLUE) + case class Cyan(text: String) extends Highlight(Console.CYAN) + case class Black(text: String) extends Highlight(Console.BLACK) + case class Green(text: String) extends Highlight(Console.GREEN) + case class White(text: String) extends Highlight(Console.WHITE) + case class Yellow(text: String) extends Highlight(Console.YELLOW) + case class Magenta(text: String) extends Highlight(Console.MAGENTA) + + case class RedB(text: String) extends Highlight(Console.RED_B) + case class BlueB(text: String) extends Highlight(Console.BLUE_B) + case class CyanB(text: String) extends Highlight(Console.CYAN_B) + case class BlackB(text: String) extends Highlight(Console.BLACK_B) + case class GreenB(text: String) extends Highlight(Console.GREEN_B) + case class WhiteB(text: String) extends Highlight(Console.WHITE_B) + case class YellowB(text: String) extends Highlight(Console.YELLOW_B) + case class MagentaB(text: String) extends Highlight(Console.MAGENTA_B) + + case class Bold(text: String) extends Modifier(Console.BOLD, text) + case class Underlined(text: String) extends Modifier(Console.UNDERLINED, text) } diff --git a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala index a00813328..b532d05c2 100644 --- a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala +++ b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala @@ -37,7 +37,7 @@ class ConsoleReporter( /** Prints the message with the given position indication. */ def printMessageAndPos(msg: String, pos: SourcePosition, kind: String = "")(implicit ctx: Context): Unit = { val posStr = if (pos.exists) s"$pos: " else "" - printMessage(posStr + kind + msg) + printMessage(s"${posStr}$kind: $msg") if (pos.exists) { printSourceLine(pos) printColumnMarker(pos) diff --git a/src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala b/src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala index 4be325b63..99ccca4cc 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala @@ -7,7 +7,7 @@ import util.{SourcePosition, NoSourcePosition} import core.Contexts.Context object MessageCreator { - implicit def toNoExplanation(str: String) = + implicit def toNoExplanation(str: String): MessageCreator = new NoExplanation(str) } diff --git a/src/dotty/tools/dotc/typer/ErrorReporting.scala b/src/dotty/tools/dotc/typer/ErrorReporting.scala index c8e76aa97..43c093510 100644 --- a/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -131,9 +131,9 @@ object ErrorReporting { val found1 = reported(found) reported.setVariance(-1) val expected1 = reported(expected) - ex"""type mismatch: - | found : $found1 - | required: $expected1""" + whyNoMatchStr(found, expected) + ex"""|type mismatch: + |found: $found1 + |required: $expected1""".stripMargin + whyNoMatchStr(found, expected) } /** Format `raw` implicitNotFound argument, replacing all diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index f161fefe3..39e5f5ead 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -23,7 +23,8 @@ class tests extends CompilerTest { val defaultOutputDir = "./out/" implicit val defaultOptions = noCheckOptions ++ List( - "-Yno-deep-subtypes", "-Yno-double-bindings", "-Yforce-sbt-phases", "-d", defaultOutputDir) ++ { + "-Yno-deep-subtypes", "-Yno-double-bindings", "-Yforce-sbt-phases", "-color:never", + "-d", defaultOutputDir) ++ { if (isRunByJenkins) List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef") // should be Ycheck:all, but #725 else List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef") } diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala index dea6a30b1..942948f08 100644 --- a/test/test/CompilerTest.scala +++ b/test/test/CompilerTest.scala @@ -5,6 +5,7 @@ import dotty.partest.DPConfig import dotty.tools.dotc.{Main, Bench, Driver} import dotty.tools.dotc.interfaces.Diagnostic.ERROR import dotty.tools.dotc.reporting._ +import diagnostic.Message import dotty.tools.dotc.util.SourcePosition import dotty.tools.dotc.config.CompilerCommand import dotty.tools.io.PlainFile @@ -237,13 +238,13 @@ abstract class CompilerTest { val storeReporter = new Reporter with UniqueMessagePositions with HideNonSensicalMessages { private val consoleReporter = new ConsoleReporter() private val innerStoreReporter = new StoreReporter(consoleReporter) - def doReport(d: Diagnostic)(implicit ctx: Context): Unit = { - if (d.level == ERROR) { + def doReport(m: Message)(implicit ctx: Context): Unit = { + if (m.level == ERROR) { innerStoreReporter.flush() - consoleReporter.doReport(d) + consoleReporter.doReport(m) } - else if (errorCount > 0) consoleReporter.doReport(d) - else innerStoreReporter.doReport(d) + else if (errorCount > 0) consoleReporter.doReport(m) + else innerStoreReporter.doReport(m) } } val reporter = processor.process(allArgs, storeReporter) diff --git a/test/test/OtherEntryPointsTest.scala b/test/test/OtherEntryPointsTest.scala index 5f8681d38..824034055 100644 --- a/test/test/OtherEntryPointsTest.scala +++ b/test/test/OtherEntryPointsTest.scala @@ -5,6 +5,7 @@ import org.junit.Assert._ import dotty.tools.dotc.Main import dotty.tools.dotc.interfaces.{CompilerCallback, SourceFile} import dotty.tools.dotc.reporting._ +import dotty.tools.dotc.reporting.diagnostic.Message import dotty.tools.dotc.core.Contexts._ import java.io.File import scala.collection.mutable.ListBuffer @@ -50,7 +51,7 @@ class OtherEntryPointsTest { private class CustomReporter extends Reporter with UniqueMessagePositions with HideNonSensicalMessages { - def doReport(d: Diagnostic)(implicit ctx: Context): Unit = { + def doReport(m: Message)(implicit ctx: Context): Unit = { } } diff --git a/tests/repl/errmsgs.check b/tests/repl/errmsgs.check index d8e863a28..e32e72d1f 100644 --- a/tests/repl/errmsgs.check +++ b/tests/repl/errmsgs.check @@ -1,41 +1,41 @@ scala> class Inv[T](x: T) defined class Inv scala> val x: List[String] = List(1) -<console>:4: error: type mismatch: - found : Int(1) - required: String +<console>:4: Error: type mismatch: +found: Int(1) +required: String val x: List[String] = List(1) ^ scala> val y: List[List[String]] = List(List(1)) -<console>:4: error: type mismatch: - found : Int(1) - required: String +<console>:4: Error: type mismatch: +found: Int(1) +required: String val y: List[List[String]] = List(List(1)) ^ scala> val z: (List[String], List[Int]) = (List(1), List("a")) -<console>:4: error: type mismatch: - found : Int(1) - required: String +<console>:4: Error: type mismatch: +found: Int(1) +required: String val z: (List[String], List[Int]) = (List(1), List("a")) ^ -<console>:4: error: type mismatch: - found : String("a") - required: Int +<console>:4: Error: type mismatch: +found: String("a") +required: Int val z: (List[String], List[Int]) = (List(1), List("a")) ^ scala> val a: Inv[String] = new Inv(new Inv(1)) -<console>:5: error: type mismatch: - found : Inv[T] - required: String +<console>:5: Error: type mismatch: +found: Inv[T] +required: String where T is a type variable with constraint >: Int(1) val a: Inv[String] = new Inv(new Inv(1)) ^ scala> val b: Inv[String] = new Inv(1) -<console>:5: error: type mismatch: - found : Int(1) - required: String +<console>:5: Error: type mismatch: +found: Int(1) +required: String val b: Inv[String] = new Inv(1) ^ scala> abstract class C { @@ -53,18 +53,18 @@ scala> abstract class C { } } } -<console>:9: error: type mismatch: - found : C.this.T(C.this.x) - required: T' +<console>:9: Error: type mismatch: +found: C.this.T(C.this.x) +required: T' where T is a type in class C T' is a type in the initalizer of value s which is an alias of String var y: T = x ^ -<console>:13: error: type mismatch: - found : T(y) - required: T' +<console>:13: Error: type mismatch: +found: T(y) +required: T' where T is a type in the initalizer of value s which is an alias of String T' is a type in method f which is an alias of Int diff --git a/tests/repl/imports.check b/tests/repl/imports.check index 3a7e9341e..50b7a93d7 100644 --- a/tests/repl/imports.check +++ b/tests/repl/imports.check @@ -7,14 +7,14 @@ defined module o scala> import o._ import o._ scala> buf += xs -<console>:11: error: type mismatch: - found : scala.collection.immutable.List[Int](o.xs) - required: String +<console>:11: Error: type mismatch: +found: scala.collection.immutable.List[Int](o.xs) +required: String buf += xs ^ -<console>:11: error: type mismatch: - found : String - required: scala.collection.mutable.ListBuffer[Int] +<console>:11: Error: type mismatch: +found: String +required: scala.collection.mutable.ListBuffer[Int] buf += xs ^ scala> buf ++= xs |