diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-09-14 17:52:11 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-10-10 13:25:32 +0200 |
commit | 281dbb553b20ca16dd9e749acdfe39129e20fa28 (patch) | |
tree | a21e8339e443fddd3ff3b9f80435d59f92708d6e /src/dotty/tools/dotc/reporting/Reporter.scala | |
parent | 3bb27d468cb06894c72b9f2cfba854ad49d68a74 (diff) | |
download | dotty-281dbb553b20ca16dd9e749acdfe39129e20fa28.tar.gz dotty-281dbb553b20ca16dd9e749acdfe39129e20fa28.tar.bz2 dotty-281dbb553b20ca16dd9e749acdfe39129e20fa28.zip |
Add initial structure for improved explanations of error messages
Diffstat (limited to 'src/dotty/tools/dotc/reporting/Reporter.scala')
-rw-r--r-- | src/dotty/tools/dotc/reporting/Reporter.scala | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala index 75113d823..eb9a10a59 100644 --- a/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/src/dotty/tools/dotc/reporting/Reporter.scala @@ -13,6 +13,7 @@ import java.lang.System.currentTimeMillis import core.Mode import interfaces.Diagnostic.{ERROR, WARNING, INFO} import dotty.tools.dotc.core.Symbols.Symbol +import ErrorExplanations._ object Reporter { class Error(msgFn: => String, pos: SourcePosition) extends Diagnostic(msgFn, pos, ERROR) @@ -95,6 +96,12 @@ trait Reporting { this: Context => def warning(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = reporter.report(new Warning(msg, pos)) + def explainWarning(expl: => Explanation, pos: SourcePosition = NoSourcePosition): Unit = { + warning(expl.msg, pos) + if (this.shouldExplain(expl)) + reporter.report(new Info(expl.explanation, NoSourcePosition)) + } + def strictWarning(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = if (this.settings.strict.value) error(msg, pos) else warning(msg + "\n(This would be an error under strict mode)", pos) @@ -104,6 +111,12 @@ trait Reporting { this: Context => reporter.report(new Error(msg, pos)) } + def explainError(expl: => Explanation, pos: SourcePosition = NoSourcePosition): Unit = { + error(expl.msg, pos) + if (this.shouldExplain(expl)) + reporter.report(new Info(expl.explanation, NoSourcePosition)) + } + def errorOrMigrationWarning(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = if (ctx.scala2Mode) migrationWarning(msg, pos) else error(msg, pos) |