diff options
-rw-r--r-- | src/dotty/tools/dotc/printing/Showable.scala | 7 | ||||
-rw-r--r-- | src/dotty/tools/dotc/reporting/Reporter.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Mode.scala | 3 |
3 files changed, 12 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/printing/Showable.scala b/src/dotty/tools/dotc/printing/Showable.scala index 550d80060..37de053cb 100644 --- a/src/dotty/tools/dotc/printing/Showable.scala +++ b/src/dotty/tools/dotc/printing/Showable.scala @@ -5,6 +5,7 @@ import core._ import Contexts._, Texts._, Decorators._ import config.Config.summarizeDepth +import scala.util.control.NonFatal trait Showable extends Any { @@ -20,7 +21,11 @@ trait Showable extends Any { def fallbackToText(printer: Printer): Text = toString /** The string representation of this showable element. */ - def show(implicit ctx: Context): String = toText(ctx.printer).show + def show(implicit ctx: Context): String = + try toText(ctx.printer).show + catch { + case NonFatal(ex) => s"[cannot display due to $ex, raw string = $toString]" + } /** The summarized string representation of this showable element. * Recursion depth is limited to some smallish value. Default is diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala index 71a908397..0979b5b19 100644 --- a/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/src/dotty/tools/dotc/reporting/Reporter.scala @@ -11,6 +11,7 @@ import config.Settings.Setting import config.Printers import java.lang.System.currentTimeMillis import typer.ErrorReporting.DiagnosticString +import typer.Mode object Reporter { @@ -215,7 +216,7 @@ abstract class Reporter { } def report(d: Diagnostic)(implicit ctx: Context): Unit = if (!isHidden(d)) { - doReport(d) + doReport(d)(ctx.addMode(Mode.Printing)) d match { case d: ConditionalWarning if !d.enablingOption.value => unreportedWarnings(d.enablingOption.name) += 1 case d: Warning => warningCount += 1 @@ -248,7 +249,7 @@ abstract class Reporter { } /** Should this diagnostic not be reported at all? */ - def isHidden(d: Diagnostic)(implicit ctx: Context): Boolean = false + def isHidden(d: Diagnostic)(implicit ctx: Context): Boolean = ctx.mode.is(Mode.Printing) /** Does this reporter contain not yet reported errors or warnings? */ def hasPending: Boolean = false diff --git a/src/dotty/tools/dotc/typer/Mode.scala b/src/dotty/tools/dotc/typer/Mode.scala index b585cc793..8889cf604 100644 --- a/src/dotty/tools/dotc/typer/Mode.scala +++ b/src/dotty/tools/dotc/typer/Mode.scala @@ -63,6 +63,9 @@ object Mode { */ val AllowDependentFunctions = newMode(9, "AllowDependentFunctions") + /** We are currently printing something: avoid to produce more logs about + * the printing + */ val Printing = newMode(10, "Printing") val PatternOrType = Pattern | Type |