File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/dotty/tools/dotc/typer Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -105,4 +105,32 @@ object ErrorReporting {
105
105
106
106
def err (implicit ctx : Context ): Errors = new Errors
107
107
108
+ /** The d string interpolator works like the i string interpolator, but marks nonsensical errors
109
+ * using `<nonsensical>...</nonsensical>` tags.
110
+ * Note: Instead of these tags, it would be nicer to return a data structure containing the message string
111
+ * and a boolean indicating whether the message is sensical, but then we cannot use string operations
112
+ * like concatenation, stripMargin etc on the values returned by d"...", and in the current error
113
+ * message composition methods, this is crucial.
114
+ */
115
+ implicit class DiagnosticString (val sc : StringContext ) extends AnyVal {
116
+ import DiagnosticString ._
117
+ def d (args : Any * )(implicit ctx : Context ): String = {
118
+ def isSensical (arg : Any ): Boolean = arg match {
119
+ case tpe : Type if tpe.isErroneous => false
120
+ case NoType => false
121
+ case sym : Symbol if sym.isCompleted =>
122
+ sym.info != ErrorType && sym.info != TypeAlias (ErrorType ) && sym.info != NoType
123
+ case _ => true
124
+ }
125
+
126
+ val s = new InfoString (sc).i(args)
127
+ if (args.forall(isSensical(_))) s else nonSensicalStartTag + s + nonSensicalEndTag
128
+ }
129
+ }
130
+
131
+ object DiagnosticString {
132
+ final val nonSensicalStartTag = " <nonsensical>"
133
+ final val nonSensicalEndTag = " </nonsensical>"
134
+ }
135
+
108
136
}
You can’t perform that action at this time.
0 commit comments