From f8456fc71e0fba8c92eb2069a7abc872a59c2567 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Thu, 15 Sep 2016 22:28:30 +0200 Subject: Add error kind to diagnostic --- .../tools/dotc/reporting/ConsoleReporter.scala | 22 +++++----------- src/dotty/tools/dotc/reporting/Diagnostic.scala | 2 +- src/dotty/tools/dotc/reporting/ErrorMessages.scala | 2 +- src/dotty/tools/dotc/reporting/Reporter.scala | 30 +++++++++++----------- 4 files changed, 23 insertions(+), 33 deletions(-) (limited to 'src/dotty/tools/dotc/reporting') diff --git a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala index a681c1552..5db549b7b 100644 --- a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala +++ b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala @@ -22,17 +22,6 @@ class ConsoleReporter( /** maximal number of error messages to be printed */ protected def ErrorLimit = 100 -<<<<<<< HEAD - def printPos(pos: SourcePosition): Unit = - if (pos.exists) { - printMessage(pos.lineContent.stripLineEnd) - printMessage(" " * pos.column + "^") - if (pos.outer.exists) { - printMessage(s"\n... this location is in code that was inlined at ${pos.outer}:\n") - printPos(pos.outer) - } - } -======= def sourceLine(pos: SourcePosition): (String, Int) = { val lineNum = s"${pos.line}:" (lineNum + hl"${pos.lineContent.stripLineEnd}", lineNum.length) @@ -78,8 +67,9 @@ class ConsoleReporter( printStr(pos.outer) + "\n" + "-" * ctx.settings.pageWidth.value } else "" - s"${Console.CYAN}$kind: $file " + - "-" * math.max(ctx.settings.pageWidth.value - file.length - kind.length - 1, 0) + + val prefix = s"${Console.CYAN}-- $kind: $file " + prefix + + ("-" * math.max(ctx.settings.pageWidth.value - prefix.replaceAll("\u001B\\[[;\\d]*m", "").length, 0)) + "\n" + outer + NoColor } else "" @@ -101,13 +91,13 @@ class ConsoleReporter( override def doReport(d: Diagnostic)(implicit ctx: Context): Unit = d match { case d: Error => - printMessageAndPos(d.message, d.pos, "Error in") + printMessageAndPos(d.message, d.pos, d.kind) if (ctx.settings.prompt.value) displayPrompt() case d: ConditionalWarning if !d.enablingOption.value => case d: MigrationWarning => - printMessageAndPos(d.message, d.pos, "Migration Warning in") + printMessageAndPos(d.message, d.pos, d.kind) case d: Warning => - printMessageAndPos(d.message, d.pos, "Warning in") + printMessageAndPos(d.message, d.pos, d.kind) case _ => printMessageAndPos(d.message, d.pos) } diff --git a/src/dotty/tools/dotc/reporting/Diagnostic.scala b/src/dotty/tools/dotc/reporting/Diagnostic.scala index bcf55e993..d08636802 100644 --- a/src/dotty/tools/dotc/reporting/Diagnostic.scala +++ b/src/dotty/tools/dotc/reporting/Diagnostic.scala @@ -11,7 +11,7 @@ object Diagnostic { val nonSensicalEndTag = "" } -class Diagnostic(msgFn: => String, val pos: SourcePosition, val level: Int) +class Diagnostic(msgFn: => String, val pos: SourcePosition, val level: Int, val kind: String) extends Exception with interfaces.Diagnostic { import Diagnostic._ private var myMsg: String = null diff --git a/src/dotty/tools/dotc/reporting/ErrorMessages.scala b/src/dotty/tools/dotc/reporting/ErrorMessages.scala index 7186ccbe2..2b4c0db7e 100644 --- a/src/dotty/tools/dotc/reporting/ErrorMessages.scala +++ b/src/dotty/tools/dotc/reporting/ErrorMessages.scala @@ -110,7 +110,7 @@ object ErrorMessages { | |$caseDef | - |`${bind.name}` is not unique. Rename one of the binds!""".stripMargin + |`${bind.name}` is not unique. Rename one of the bound variables!""".stripMargin } } } diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala index 401938859..db0922b2e 100644 --- a/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/src/dotty/tools/dotc/reporting/Reporter.scala @@ -16,23 +16,23 @@ import dotty.tools.dotc.core.Symbols.Symbol import ErrorMessages._ object Reporter { - class Error(msgFn: => String, pos: SourcePosition) extends Diagnostic(msgFn, pos, ERROR) - class Warning(msgFn: => String, pos: SourcePosition) extends Diagnostic(msgFn, pos, WARNING) - class Info(msgFn: => String, pos: SourcePosition) extends Diagnostic(msgFn, pos, INFO) + class Error(msgFn: => String, pos: SourcePosition, kind: String = "Error") extends Diagnostic(msgFn, pos, ERROR, kind) + class Warning(msgFn: => String, pos: SourcePosition, kind: String = "Warning") extends Diagnostic(msgFn, pos, WARNING, kind) + class Info(msgFn: => String, pos: SourcePosition, kind: String = "Info") extends Diagnostic(msgFn, pos, INFO, kind) - abstract class ConditionalWarning(msgFn: => String, pos: SourcePosition) extends Warning(msgFn, pos) { + abstract class ConditionalWarning(msgFn: => String, pos: SourcePosition, kind: String) extends Warning(msgFn, pos, kind) { def enablingOption(implicit ctx: Context): Setting[Boolean] } - class FeatureWarning(msgFn: => String, pos: SourcePosition) extends ConditionalWarning(msgFn, pos) { + class FeatureWarning(msgFn: => String, pos: SourcePosition, kind: String = "Feature Warning") extends ConditionalWarning(msgFn, pos, kind) { def enablingOption(implicit ctx: Context) = ctx.settings.feature } - class UncheckedWarning(msgFn: => String, pos: SourcePosition) extends ConditionalWarning(msgFn, pos) { + class UncheckedWarning(msgFn: => String, pos: SourcePosition, kind: String = "Unchecked Warning") extends ConditionalWarning(msgFn, pos, kind) { def enablingOption(implicit ctx: Context) = ctx.settings.unchecked } - class DeprecationWarning(msgFn: => String, pos: SourcePosition) extends ConditionalWarning(msgFn, pos) { + class DeprecationWarning(msgFn: => String, pos: SourcePosition, kind: String = "Deprecation Warning") extends ConditionalWarning(msgFn, pos, kind) { def enablingOption(implicit ctx: Context) = ctx.settings.deprecation } - class MigrationWarning(msgFn: => String, pos: SourcePosition) extends ConditionalWarning(msgFn, pos) { + class MigrationWarning(msgFn: => String, pos: SourcePosition, kind: String = "Migration Warning") extends ConditionalWarning(msgFn, pos, kind) { def enablingOption(implicit ctx: Context) = ctx.settings.migration } @@ -56,19 +56,19 @@ trait Reporting { this: Context => if (this.settings.verbose.value) this.echo(msg, pos) def echo(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new Info(msg, pos)) + reporter.report(new Info(msg, pos, "Info")) def deprecationWarning(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new DeprecationWarning(msg, pos)) + reporter.report(new DeprecationWarning(msg, pos, "Deprecation Warning")) def migrationWarning(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new MigrationWarning(msg, pos)) + reporter.report(new MigrationWarning(msg, pos, "Migration Warning")) def uncheckedWarning(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new UncheckedWarning(msg, pos)) + reporter.report(new UncheckedWarning(msg, pos, "Unchecked Warning")) def featureWarning(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new FeatureWarning(msg, pos)) + reporter.report(new FeatureWarning(msg, pos, "Feature Warning")) def featureWarning(feature: String, featureDescription: String, isScala2Feature: Boolean, featureUseSite: Symbol, required: Boolean, pos: SourcePosition): Unit = { @@ -97,7 +97,7 @@ trait Reporting { this: Context => reporter.report(new Warning(msg, pos)) def explainWarning(err: => ErrorMessage, pos: SourcePosition = NoSourcePosition): Unit = { - warning(err.msg, pos) + reporter.report(new Warning(err.msg, pos, s"${err.kind} warning")) if (this.shouldExplain(err)) reporter.report(new Info(err.explanation, NoSourcePosition)) } @@ -112,7 +112,7 @@ trait Reporting { this: Context => } def explainError(err: => ErrorMessage, pos: SourcePosition = NoSourcePosition): Unit = { - error(err.msg, pos) + reporter.report(new Error(err.msg, pos, s"${err.kind} error")) if (this.shouldExplain(err)) reporter.report(new Info(err.explanation, NoSourcePosition)) } -- cgit v1.2.3