aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-09 13:49:46 +0100
committerFelix Mulder <felix.mulder@gmail.com>2016-11-09 13:49:46 +0100
commit7332e9c1df756f6898e58231183517fefe93604d (patch)
treefdd1078db6fb2fe42e379cf3532e2a6d7e7340c1 /src
parente0839e97cac2d212aae8eebbf3f828f91a27ddab (diff)
downloaddotty-7332e9c1df756f6898e58231183517fefe93604d.tar.gz
dotty-7332e9c1df756f6898e58231183517fefe93604d.tar.bz2
dotty-7332e9c1df756f6898e58231183517fefe93604d.zip
Change `ClassicReporter` to `TestReporter` in test sources
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/reporting/ClassicReporter.scala85
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/messages.scala19
-rw-r--r--src/dotty/tools/dotc/transform/patmat/Space.scala12
3 files changed, 23 insertions, 93 deletions
diff --git a/src/dotty/tools/dotc/reporting/ClassicReporter.scala b/src/dotty/tools/dotc/reporting/ClassicReporter.scala
deleted file mode 100644
index bd881eb4f..000000000
--- a/src/dotty/tools/dotc/reporting/ClassicReporter.scala
+++ /dev/null
@@ -1,85 +0,0 @@
-package dotty.tools
-package dotc
-package reporting
-
-import scala.collection.mutable
-import util.SourcePosition
-import core.Contexts._
-import Reporter._
-import java.io.{ BufferedReader, IOException, PrintWriter }
-import scala.reflect.internal.util._
-import diagnostic.{ Message, MessageContainer, NoExplanation }
-import diagnostic.messages._
-
-/**
- * This class implements a Reporter that displays messages on a text
- * console.
- */
-class ClassicReporter(
- reader: BufferedReader = Console.in,
- writer: PrintWriter = new PrintWriter(Console.err, true))
- 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) {
- printMessage(pos.lineContent.stripLineEnd)
- printMessage(" " * pos.column + "^")
- if (pos.outer.exists) {
- printMessage(s"\n... this location is in code that was inlined at ${pos.outer}:\n")
- printPos(pos.outer)
- }
- }
-
- /** Prints the message. */
- def printMessage(msg: String): Unit = { writer.print(msg + "\n"); writer.flush() }
-
- /** Prints the message with the given position indication. */
- def printMessageAndPos(msg: String, pos: SourcePosition)(implicit ctx: Context): Unit = {
- val posStr = if (pos.exists) s"$pos: " else ""
- printMessage(posStr + msg)
- printPos(pos)
- }
-
- override def doReport(m: MessageContainer)(implicit ctx: Context): Unit = m match {
- case m: Error =>
- printMessageAndPos(s"error: ${m.contained}", m.pos)
- if (ctx.settings.prompt.value) displayPrompt()
- case m: ConditionalWarning if !m.enablingOption.value =>
- case m: FeatureWarning =>
- printMessageAndPos(s"feature warning: ${m.contained.msg}", m.pos)
- case m: DeprecationWarning =>
- printMessageAndPos(s"deprecation warning: ${m.contained.msg}", m.pos)
- case m: UncheckedWarning =>
- printMessageAndPos(s"unchecked warning: ${m.contained.msg}", m.pos)
- case m: Info =>
- printMessageAndPos(m.contained.msg, m.pos)
- case m: MigrationWarning =>
- printMessageAndPos(s"migration warning: ${m.contained.msg}", m.pos)
- case m: Warning =>
- printMessageAndPos(s"warning: ${m.contained.msg}", m.pos)
- case _ =>
- printMessageAndPos(m.contained.msg, m.pos)
- }
-
- def displayPrompt(): Unit = {
- writer.print("\na)bort, s)tack, r)esume: ")
- writer.flush()
- if (reader != null) {
- val response = reader.read().asInstanceOf[Char].toLower
- if (response == 'a' || response == 's') {
- Thread.dumpStack()
- if (response == 'a')
- sys.exit(1)
- }
- writer.print("\n")
- writer.flush()
- }
- }
-
- override def flush()(implicit ctx: Context): Unit = { writer.flush() }
-}
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index 65fafd092..649f2a8f8 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -768,4 +768,23 @@ object messages {
| - null
|"""
}
+
+ case class PatternMatchExhaustivity(uncovered: String)(implicit ctx: Context)
+ extends Message(29) {
+ val kind = "Pattern Match Exhaustivity"
+ val msg =
+ hl"""|match may not be exhaustive.
+ |
+ |It would fail on: $uncovered"""
+
+
+ val explanation = ""
+ }
+
+ case class MatchCaseUnreachable()(implicit ctx: Context)
+ extends Message(30) {
+ val kind = s"""Match ${hl"case"} Unreachable"""
+ val msg = "unreachable code"
+ val explanation = ""
+ }
}
diff --git a/src/dotty/tools/dotc/transform/patmat/Space.scala b/src/dotty/tools/dotc/transform/patmat/Space.scala
index 830d0f938..8d926fcf0 100644
--- a/src/dotty/tools/dotc/transform/patmat/Space.scala
+++ b/src/dotty/tools/dotc/transform/patmat/Space.scala
@@ -12,6 +12,7 @@ import core.Symbols._
import core.StdNames._
import core.NameOps._
import core.Constants._
+import reporting.diagnostic.messages._
/** Space logic for checking exhaustivity and unreachability of pattern matching
*
@@ -586,13 +587,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
val patternSpace = cases.map(x => project(x.pat)).reduce((a, b) => Or(List(a, b)))
val uncovered = simplify(minus(Typ(selTyp, true), patternSpace))
- if (uncovered != Empty) {
- ctx.warning(
- "match may not be exhaustive.\n" +
- s"It would fail on the following input: " +
- show(uncovered), _match.pos
- )
- }
+ if (uncovered != Empty)
+ ctx.warning(PatternMatchExhaustivity(show(uncovered)), _match.pos)
}
def checkRedundancy(_match: Match): Unit = {
@@ -612,7 +608,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
val curr = project(cases(i).pat)
if (isSubspace(curr, prevs)) {
- ctx.warning("unreachable code", cases(i).body.pos)
+ ctx.warning(MatchCaseUnreachable(), cases(i).body.pos)
}
}
}