aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-10-03 18:21:28 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-10-10 13:25:37 +0200
commitd2b620541b18bb50d2a2b89194e1778c64bba567 (patch)
treea37b2bc37deda4e281d3279ff931ed8effdef28f /src/dotty/tools/dotc/reporting
parent29d19ba41622b1a904d4960869866c0967db6c37 (diff)
downloaddotty-d2b620541b18bb50d2a2b89194e1778c64bba567.tar.gz
dotty-d2b620541b18bb50d2a2b89194e1778c64bba567.tar.bz2
dotty-d2b620541b18bb50d2a2b89194e1778c64bba567.zip
Insert message "inline" into multiline code at point
Diffstat (limited to 'src/dotty/tools/dotc/reporting')
-rw-r--r--src/dotty/tools/dotc/reporting/ConsoleReporter.scala12
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/Message.scala8
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/messages.scala34
3 files changed, 25 insertions, 29 deletions
diff --git a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
index 6ebd53bea..82edd6a83 100644
--- a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
+++ b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
@@ -32,9 +32,10 @@ class ConsoleReporter(
def stripColor(str: String): String =
str.replaceAll("\u001B\\[[;\\d]*m", "")
- def sourceLines(pos: SourcePosition)(implicit ctx: Context): (List[String], Int) = {
+ def sourceLines(pos: SourcePosition)(implicit ctx: Context): (List[String], List[String], Int) = {
var maxLen = Int.MinValue
- val lines = pos.lines
+ def render(xs: List[Int]) =
+ xs.map(pos.source.offsetToLine(_))
.map { lineNbr =>
val prefix = s"${lineNbr + 1} |"
maxLen = math.max(maxLen, prefix.length)
@@ -45,7 +46,8 @@ class ConsoleReporter(
hl"$lnum$line"
}
- (lines, maxLen)
+ val (before, after) = pos.beforeAndAfterPoint
+ (render(before), render(after), maxLen)
}
def columnMarker(pos: SourcePosition, offset: Int)(implicit ctx: Context) = {
@@ -95,11 +97,11 @@ class ConsoleReporter(
def printMessageAndPos(msg: Message, pos: SourcePosition, diagnosticLevel: String)(implicit ctx: Context): Unit = {
printMessage(posStr(pos, diagnosticLevel, msg))
if (pos.exists) {
- val (srcLines, offset) = sourceLines(pos)
+ val (srcBefore, srcAfter, offset) = sourceLines(pos)
val marker = columnMarker(pos, offset)
val err = errorMsg(pos, msg.msg, offset)
- printMessage((srcLines ::: marker :: err :: Nil).mkString("\n"))
+ printMessage((srcBefore ::: marker :: err :: srcAfter).mkString("\n"))
} else printMessage(msg.msg)
}
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/Message.scala b/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
index bdc899ea8..8b1f65673 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
@@ -15,6 +15,14 @@ object Message {
new NoExplanation(str)
}
+/** A `Message` contains all semantic information necessary to easily
+ * comprehend what caused the message to be logged. Each message can be turned
+ * into a `MessageContainer` which contains the log level and can later be
+ * consumed by a subclass of `Reporter`.
+ *
+ * @param errorId a unique number identifying the message, this will later be
+ * used to reference documentation online
+ */
abstract class Message(val errorId: Int) { self =>
import messages._
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index e2b99af41..cc062ff92 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -90,8 +90,10 @@ object messages {
}
val code1 =
- s"""|try $tryString catch {
- | case t: Throwable => ???
+ s"""|import scala.util.control.NonFatal
+ |
+ |try $tryString catch {
+ | case NonFatal(e) => ???
|}""".stripMargin
val code2 =
@@ -108,7 +110,10 @@ object messages {
|It is also possible to follow a ${"try"} immediately by a ${"finally"} - letting the
|exception propagate - but still allowing for some clean up in ${"finally"}:
|
- |$code2""".stripMargin
+ |$code2
+ |
+ |It is recommended to use the ${"NonFatal"} extractor to catch all exceptions as it
+ |correctly handles transfer functions like ${"return"}.""".stripMargin
}
}
@@ -133,29 +138,10 @@ object messages {
val kind = "Syntax"
val msg =
hl"""${"with"} as a type operator has been deprecated; use `&' instead"""
- val explanation = {
- val codeBlock1 =
- """|trait A {
- | type T = Int
- |}
- |
- |trait B {
- | type T = Double
- |}""".stripMargin
-
+ val explanation =
hl"""|Dotty introduces intersection types - `&' types. These replace the
|use of the ${"with"} keyword. There are a few differences in
- |semantics between intersection types and using `${"with"}'.
- |
- |`${"A with B"}' is ordered, `${"A & B"}' is not.
- |
- |In:
- |
- |$codeBlock1
- |
- |The type of `${"T"}' in `${"A with B"}' is ${"Int"} whereas in `${"A & B"}'
- |the type of `${"T"}' is ${"Int & Double"}.""".stripMargin
- }
+ |semantics between intersection types and using `${"with"}'.""".stripMargin
}
case class CaseClassMissingParamList(cdef: untpd.TypeDef)(implicit ctx: Context)