diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 6405b8aafbc0..cfe6176df4f5 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -393,6 +393,7 @@ private sealed trait YSettings: val YshowVarBounds: Setting[Boolean] = BooleanSetting("-Yshow-var-bounds", "Print type variables with their bounds.") val YnoDecodeStacktraces: Setting[Boolean] = BooleanSetting("-Yno-decode-stacktraces", "Show raw StackOverflow stacktraces, instead of decoding them into triggering operations.") + val YnoEnrichErrorMessages: Setting[Boolean] = BooleanSetting("-Yno-enrich-error-messages", "Show raw error messages, instead of enriching them with contextual information.") val Yinstrument: Setting[Boolean] = BooleanSetting("-Yinstrument", "Add instrumentation code that counts allocations and closure creations.") val YinstrumentDefs: Setting[Boolean] = BooleanSetting("-Yinstrument-defs", "Add instrumentation code that counts method calls; needs -Yinstrument to be set, too.") diff --git a/compiler/src/dotty/tools/dotc/report.scala b/compiler/src/dotty/tools/dotc/report.scala index 247e67b5be36..75261fb6890e 100644 --- a/compiler/src/dotty/tools/dotc/report.scala +++ b/compiler/src/dotty/tools/dotc/report.scala @@ -132,7 +132,13 @@ object report: private object messageRendering extends MessageRendering // Should only be called from Run#enrichErrorMessage. - def enrichErrorMessage(errorMessage: String)(using Context): String = try { + def enrichErrorMessage(errorMessage: String)(using Context): String = + if ctx.settings.YnoEnrichErrorMessages.value then errorMessage + else try enrichErrorMessage1(errorMessage) + catch case _: Throwable => errorMessage // don't introduce new errors trying to report errors, so swallow exceptions + + private def enrichErrorMessage1(errorMessage: String)(using Context): String = { + import untpd.*, config.Settings.* def formatExplain(pairs: List[(String, Any)]) = pairs.map((k, v) => f"$k%20s: $v").mkString("\n") val settings = ctx.settings.userSetSettings(ctx.settingsState).sortBy(_.name) @@ -155,5 +161,5 @@ object report: | |$info1 |""".stripMargin - } catch case _: Throwable => errorMessage // don't introduce new errors trying to report errors, so swallow exceptions + } end report