aboutsummaryrefslogtreecommitdiff
path: root/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala
blob: 70d18d03135c7da583e14c7acf0c2446189e2cf3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package dotty.tools
package dotc
package reporting

import scala.collection.mutable
import util.SourcePosition
import core.Contexts._
import Reporter._
import java.io.PrintWriter
import scala.reflect.internal.util._
import diagnostic.{ Message, MessageContainer, NoExplanation }
import diagnostic.messages._

class TestReporter(writer: PrintWriter) extends Reporter
with UniqueMessagePositions with HideNonSensicalMessages {

  import MessageContainer._

  /** maximal number of error messages to be printed */
  protected def ErrorLimit = 100

  def printPos(pos: SourcePosition): Unit =
    if (pos.exists) {
      if (pos.outer.exists) {
        writer.println(s"\ninlined at ${pos.outer}:\n")
        printPos(pos.outer)
      }
    }

  /** Prints the message with the given position indication. */
  def printMessageAndPos(msg: String, pos: SourcePosition)(implicit ctx: Context): Unit = {
    val posStr = s"${pos.line + 1}: "
    writer.println(posStr + msg)
    printPos(pos)
  }

  override def doReport(m: MessageContainer)(implicit ctx: Context): Unit = {
    // Here we add extra information that we should know about the error message
    val extra = m.contained match {
      case pm: PatternMatchExhaustivity => s": ${pm.uncovered}"
      case _ => ""
    }

    m match {
      case m: Error =>
        printMessageAndPos(m.contained.kind + extra, m.pos)
      case w: Warning =>
        printMessageAndPos(w.contained.kind + extra, w.pos)
      case _ =>
    }
  }
}