Skip to content

Commit ba8b497

Browse files
committed
Add error kind to diagnostic
1 parent 3635333 commit ba8b497

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

interfaces/src/main/java/dotty/tools/dotc/interfaces/Diagnostic.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public interface Diagnostic {
1414
public static final int WARNING = 1;
1515
public static final int INFO = 0;
1616

17+
/** @return The kind of message being reported */
18+
String kind();
19+
1720
/** @return The message to report */
1821
String message();
1922

src/dotty/tools/dotc/reporting/ConsoleReporter.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ class ConsoleReporter(
6262
if (pos.exists) {
6363
val file = pos.source.file.toString
6464

65-
s"${Console.CYAN}$kind: $file " +
66-
"-" * math.max(ctx.settings.pageWidth.value - file.length - kind.length - 1, 0) +
65+
val prefix = s"${Console.CYAN}-- $kind: $file "
66+
prefix +
67+
("-" * math.max(ctx.settings.pageWidth.value - prefix.replaceAll("\u001B\\[[;\\d]*m", "").length, 0)) +
6768
NoColor
68-
}
69-
else ""
69+
} else ""
7070

7171
/** Prints the message. */
7272
def printMessage(msg: String): Unit = { writer.print(msg + "\n"); writer.flush() }
@@ -85,13 +85,13 @@ class ConsoleReporter(
8585

8686
override def doReport(d: Diagnostic)(implicit ctx: Context): Unit = d match {
8787
case d: Error =>
88-
printMessageAndPos(d.message, d.pos, "Error in")
88+
printMessageAndPos(d.message, d.pos, d.kind)
8989
if (ctx.settings.prompt.value) displayPrompt()
9090
case d: ConditionalWarning if !d.enablingOption.value =>
9191
case d: MigrationWarning =>
92-
printMessageAndPos(d.message, d.pos, "Migration Warning in")
92+
printMessageAndPos(d.message, d.pos, d.kind)
9393
case d: Warning =>
94-
printMessageAndPos(d.message, d.pos, "Warning in")
94+
printMessageAndPos(d.message, d.pos, d.kind)
9595
case _ =>
9696
printMessageAndPos(d.message, d.pos)
9797
}

src/dotty/tools/dotc/reporting/Diagnostic.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Diagnostic {
1111
val nonSensicalEndTag = "</nonsensical>"
1212
}
1313

14-
class Diagnostic(msgFn: => String, val pos: SourcePosition, val level: Int)
14+
class Diagnostic(msgFn: => String, val pos: SourcePosition, val level: Int, val kind: String)
1515
extends Exception with interfaces.Diagnostic {
1616
import Diagnostic._
1717
private var myMsg: String = null

src/dotty/tools/dotc/reporting/ErrorMessages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ object ErrorMessages {
110110
|
111111
|$caseDef
112112
|
113-
|`${bind.name}` is not unique. Rename one of the binds!""".stripMargin
113+
|`${bind.name}` is not unique. Rename one of the bound variables!""".stripMargin
114114
}
115115
}
116116
}

src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ import dotty.tools.dotc.core.Symbols.Symbol
1616
import ErrorMessages._
1717

1818
object Reporter {
19-
class Error(msgFn: => String, pos: SourcePosition) extends Diagnostic(msgFn, pos, ERROR)
20-
class Warning(msgFn: => String, pos: SourcePosition) extends Diagnostic(msgFn, pos, WARNING)
21-
class Info(msgFn: => String, pos: SourcePosition) extends Diagnostic(msgFn, pos, INFO)
19+
class Error(msgFn: => String, pos: SourcePosition, kind: String = "Error") extends Diagnostic(msgFn, pos, ERROR, kind)
20+
class Warning(msgFn: => String, pos: SourcePosition, kind: String = "Warning") extends Diagnostic(msgFn, pos, WARNING, kind)
21+
class Info(msgFn: => String, pos: SourcePosition, kind: String = "Info") extends Diagnostic(msgFn, pos, INFO, kind)
2222

23-
abstract class ConditionalWarning(msgFn: => String, pos: SourcePosition) extends Warning(msgFn, pos) {
23+
abstract class ConditionalWarning(msgFn: => String, pos: SourcePosition, kind: String) extends Warning(msgFn, pos, kind) {
2424
def enablingOption(implicit ctx: Context): Setting[Boolean]
2525
}
26-
class FeatureWarning(msgFn: => String, pos: SourcePosition) extends ConditionalWarning(msgFn, pos) {
26+
class FeatureWarning(msgFn: => String, pos: SourcePosition, kind: String = "Feature Warning") extends ConditionalWarning(msgFn, pos, kind) {
2727
def enablingOption(implicit ctx: Context) = ctx.settings.feature
2828
}
29-
class UncheckedWarning(msgFn: => String, pos: SourcePosition) extends ConditionalWarning(msgFn, pos) {
29+
class UncheckedWarning(msgFn: => String, pos: SourcePosition, kind: String = "Unchecked Warning") extends ConditionalWarning(msgFn, pos, kind) {
3030
def enablingOption(implicit ctx: Context) = ctx.settings.unchecked
3131
}
32-
class DeprecationWarning(msgFn: => String, pos: SourcePosition) extends ConditionalWarning(msgFn, pos) {
32+
class DeprecationWarning(msgFn: => String, pos: SourcePosition, kind: String = "Deprecation Warning") extends ConditionalWarning(msgFn, pos, kind) {
3333
def enablingOption(implicit ctx: Context) = ctx.settings.deprecation
3434
}
35-
class MigrationWarning(msgFn: => String, pos: SourcePosition) extends ConditionalWarning(msgFn, pos) {
35+
class MigrationWarning(msgFn: => String, pos: SourcePosition, kind: String = "Migration Warning") extends ConditionalWarning(msgFn, pos, kind) {
3636
def enablingOption(implicit ctx: Context) = ctx.settings.migration
3737
}
3838

@@ -56,19 +56,19 @@ trait Reporting { this: Context =>
5656
if (this.settings.verbose.value) this.echo(msg, pos)
5757

5858
def echo(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
59-
reporter.report(new Info(msg, pos))
59+
reporter.report(new Info(msg, pos, "Info"))
6060

6161
def deprecationWarning(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
62-
reporter.report(new DeprecationWarning(msg, pos))
62+
reporter.report(new DeprecationWarning(msg, pos, "Deprecation Warning"))
6363

6464
def migrationWarning(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
65-
reporter.report(new MigrationWarning(msg, pos))
65+
reporter.report(new MigrationWarning(msg, pos, "Migration Warning"))
6666

6767
def uncheckedWarning(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
68-
reporter.report(new UncheckedWarning(msg, pos))
68+
reporter.report(new UncheckedWarning(msg, pos, "Unchecked Warning"))
6969

7070
def featureWarning(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
71-
reporter.report(new FeatureWarning(msg, pos))
71+
reporter.report(new FeatureWarning(msg, pos, "Feature Warning"))
7272

7373
def featureWarning(feature: String, featureDescription: String, isScala2Feature: Boolean,
7474
featureUseSite: Symbol, required: Boolean, pos: SourcePosition): Unit = {
@@ -97,7 +97,7 @@ trait Reporting { this: Context =>
9797
reporter.report(new Warning(msg, pos))
9898

9999
def explainWarning(err: => ErrorMessage, pos: SourcePosition = NoSourcePosition): Unit = {
100-
warning(err.msg, pos)
100+
reporter.report(new Warning(err.msg, pos, s"${err.kind} warning"))
101101
if (this.shouldExplain(err))
102102
reporter.report(new Info(err.explanation, NoSourcePosition))
103103
}
@@ -112,7 +112,7 @@ trait Reporting { this: Context =>
112112
}
113113

114114
def explainError(err: => ErrorMessage, pos: SourcePosition = NoSourcePosition): Unit = {
115-
error(err.msg, pos)
115+
reporter.report(new Error(err.msg, pos, s"${err.kind} error"))
116116
if (this.shouldExplain(err))
117117
reporter.report(new Info(err.explanation, NoSourcePosition))
118118
}

0 commit comments

Comments
 (0)