From 73f6f1b8b1cf9221d9b7cfc48598bb240e2b8c05 Mon Sep 17 00:00:00 2001 From: Samuel Gruetter Date: Wed, 26 Mar 2014 18:59:43 +0100 Subject: add d string interpolator (marks nonsensical error messages) --- src/dotty/tools/dotc/typer/ErrorReporting.scala | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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 `...` 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 = "" + final val nonSensicalEndTag = "" + } + } \ No newline at end of file -- cgit v1.2.3