diff options
author | Martin Odersky <odersky@gmail.com> | 2015-05-20 09:46:19 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-05-21 17:41:16 +0200 |
commit | de7a5bb049fadaa2078107358e51de273a15d515 (patch) | |
tree | e1dbf243136773723142995dd32d5c1be7bcd07c /src | |
parent | 02f5ba8f72b043854aec5729f2b30fe813027435 (diff) | |
download | dotty-de7a5bb049fadaa2078107358e51de273a15d515.tar.gz dotty-de7a5bb049fadaa2078107358e51de273a15d515.tar.bz2 dotty-de7a5bb049fadaa2078107358e51de273a15d515.zip |
Harden display logic
Displaying stuff should never report an exception or cause more messages to be displayed that
relate to the displaying.
Diffstat (limited to 'src')
-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 |