aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Gruetter <samuel.gruetter@epfl.ch>2014-03-26 18:59:43 +0100
committerSamuel Gruetter <samuel.gruetter@epfl.ch>2014-04-02 14:56:26 +0200
commit73f6f1b8b1cf9221d9b7cfc48598bb240e2b8c05 (patch)
tree5210faf7a02b82bb3384b18c32fc749ff2956b03
parent094d8c57d3e45168c123b40b961fdebdca12e924 (diff)
downloaddotty-73f6f1b8b1cf9221d9b7cfc48598bb240e2b8c05.tar.gz
dotty-73f6f1b8b1cf9221d9b7cfc48598bb240e2b8c05.tar.bz2
dotty-73f6f1b8b1cf9221d9b7cfc48598bb240e2b8c05.zip
add d string interpolator (marks nonsensical error messages)
-rw-r--r--src/dotty/tools/dotc/typer/ErrorReporting.scala28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/typer/ErrorReporting.scala b/src/dotty/tools/dotc/typer/ErrorReporting.scala
index 5e7faab22..3ff1d7a7e 100644
--- a/src/dotty/tools/dotc/typer/ErrorReporting.scala
+++ b/src/dotty/tools/dotc/typer/ErrorReporting.scala
@@ -105,4 +105,32 @@ object ErrorReporting {
def err(implicit ctx: Context): Errors = new Errors
+ /** The d string interpolator works like the i string interpolator, but marks nonsensical errors
+ * using `<nonsensical>...</nonsensical>` tags.
+ * Note: Instead of these tags, it would be nicer to return a data structure containing the message string
+ * and a boolean indicating whether the message is sensical, but then we cannot use string operations
+ * like concatenation, stripMargin etc on the values returned by d"...", and in the current error
+ * message composition methods, this is crucial.
+ */
+ implicit class DiagnosticString(val sc: StringContext) extends AnyVal {
+ import DiagnosticString._
+ def d(args: Any*)(implicit ctx: Context): String = {
+ def isSensical(arg: Any): Boolean = arg match {
+ case tpe: Type if tpe.isErroneous => false
+ case NoType => false
+ case sym: Symbol if sym.isCompleted =>
+ sym.info != ErrorType && sym.info != TypeAlias(ErrorType) && sym.info != NoType
+ case _ => true
+ }
+
+ val s = new InfoString(sc).i(args)
+ if (args.forall(isSensical(_))) s else nonSensicalStartTag + s + nonSensicalEndTag
+ }
+ }
+
+ object DiagnosticString {
+ final val nonSensicalStartTag = "<nonsensical>"
+ final val nonSensicalEndTag = "</nonsensical>"
+ }
+
} \ No newline at end of file