Skip to content

Commit b120977

Browse files
committed
report: Trim down enriched error messages
The implementation here comes from porting from nsc. But I think things were done differently enough with its Global state, that make it not translate nicely here. So I'm paring it down to what I know works (at least for me): versions, settings, compilation unit. Not the tree/symbol/site stuff.
1 parent 8c1cdc2 commit b120977

File tree

1 file changed

+3
-36
lines changed

1 file changed

+3
-36
lines changed

compiler/src/dotty/tools/dotc/report.scala

+3-36
Original file line numberDiff line numberDiff line change
@@ -136,46 +136,16 @@ object report:
136136
def formatExplain(pairs: List[(String, Any)]) = pairs.map((k, v) => f"$k%20s: $v").mkString("\n")
137137

138138
val settings = ctx.settings.userSetSettings(ctx.settingsState).sortBy(_.name)
139-
val tree = ctx.tree
140-
val sym = tree.symbol
141-
val pos = tree.sourcePos
142-
val path = pos.source.path
143-
val site = ctx.outersIterator.map(_.owner).filter(sym => !sym.exists || sym.isClass || sym.is(Method)).next()
144-
145-
import untpd.*
146-
extension (tree: Tree) def summaryString: String = tree match
147-
case Literal(const) => s"Literal($const)"
148-
case Ident(name) => s"Ident(${name.decode})"
149-
case Select(qual, name) => s"Select(${qual.summaryString}, ${name.decode})"
150-
case tree: NameTree => (if tree.isType then "type " else "") + tree.name.decode
151-
case tree => s"${tree.className}${if tree.symbol.exists then s"(${tree.symbol})" else ""}"
139+
def showSetting(s: Setting[?]): String = if s.value == "" then s"${s.name} \"\"" else s"${s.name} ${s.value}"
152140

153141
val info1 = formatExplain(List(
154142
"while compiling" -> ctx.compilationUnit,
155143
"during phase" -> ctx.phase.megaPhase,
156144
"mode" -> ctx.mode,
157145
"library version" -> scala.util.Properties.versionString,
158146
"compiler version" -> dotty.tools.dotc.config.Properties.versionString,
159-
"settings" -> settings.map(s => if s.value == "" then s"${s.name} \"\"" else s"${s.name} ${s.value}").mkString(" "),
147+
"settings" -> settings.map(showSetting).mkString(" "),
160148
))
161-
val symbolInfos = if sym eq NoSymbol then List("symbol" -> sym) else List(
162-
"symbol" -> sym.showLocated,
163-
"symbol definition" -> s"${sym.showDcl} (a ${sym.className})",
164-
"symbol package" -> sym.enclosingPackageClass.fullName,
165-
"symbol owners" -> sym.showExtendedLocation,
166-
)
167-
val info2 = formatExplain(List(
168-
"tree" -> tree.summaryString,
169-
"tree position" -> (if pos.exists then s"$path:${pos.line + 1}:${pos.column}" else s"$path:<unknown>"),
170-
"tree type" -> tree.typeOpt.show,
171-
) ::: symbolInfos ::: List(
172-
"call site" -> s"${site.showLocated} in ${site.enclosingPackageClass}"
173-
))
174-
val context_s = try
175-
s""" == Source file context for tree position ==
176-
|
177-
|${messageRendering.messageAndPos(Diagnostic.Error("", pos))}""".stripMargin
178-
catch case _: Exception => "<Cannot read source file>"
179149
s"""
180150
| $errorMessage
181151
|
@@ -184,9 +154,6 @@ object report:
184154
| https://github.com/lampepfl/dotty/issues/new/choose
185155
|
186156
|$info1
187-
|
188-
|$info2
189-
|
190-
|$context_s""".stripMargin
157+
|""".stripMargin
191158
} catch case _: Throwable => errorMessage // don't introduce new errors trying to report errors, so swallow exceptions
192159
end report

0 commit comments

Comments
 (0)