Skip to content

Commit e42bb30

Browse files
committed
Change Message#errorId to type Int
1 parent f7b8980 commit e42bb30

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import java.io.{ BufferedReader, IOException, PrintWriter }
1010
import scala.reflect.internal.util._
1111
import printing.SyntaxHighlighting._
1212
import printing.Highlighting._
13-
import diagnostic.{ Message, MessageContainer }
13+
import diagnostic.{ Message, MessageContainer, NoExplanation }
1414
import diagnostic.messages._
1515

1616
/**
@@ -68,7 +68,10 @@ class ConsoleReporter(
6868
def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(implicit ctx: Context) =
6969
if (pos.exists) Blue({
7070
val file = pos.source.file.toString
71-
val errId = if (message.errorId != "") s"[${message.errorId}] " else ""
71+
val errId =
72+
if (message.errorId != NoExplanation.ID)
73+
s"[E${"0" * (3 - message.errorId.toString.length) + message.errorId}] "
74+
else ""
7275
val kind =
7376
if (message.kind == "") diagnosticLevel
7477
else s"${message.kind} $diagnosticLevel"

src/dotty/tools/dotc/reporting/diagnostic/Message.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Message {
1515
new NoExplanation(str)
1616
}
1717

18-
abstract class Message(val errorId: String) { self =>
18+
abstract class Message(val errorId: Int) { self =>
1919
import messages._
2020

2121
/** The `msg` contains the diagnostic message e.g:
@@ -81,7 +81,7 @@ abstract class Message(val errorId: String) { self =>
8181
}
8282

8383
/** The fallback `Message` containing no explanation and having no `kind` */
84-
class NoExplanation(val msg: String) extends Message("") {
84+
class NoExplanation(val msg: String) extends Message(NoExplanation.ID) {
8585
val explanation = ""
8686
val kind = ""
8787
}
@@ -90,6 +90,8 @@ class NoExplanation(val msg: String) extends Message("") {
9090
* lacks an explanation
9191
*/
9292
object NoExplanation {
93+
final val ID = -1
94+
9395
def unapply(m: Message): Option[Message] =
9496
if (m.explanation == "") Some(m)
9597
else None

src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ object messages {
8989
import dotc.ast.untpd
9090

9191
// Syntax Errors ---------------------------------------------------------- //
92-
abstract class EmptyCatchOrFinallyBlock(tryBody: untpd.Tree, errNo: String)(implicit ctx: Context)
92+
abstract class EmptyCatchOrFinallyBlock(tryBody: untpd.Tree, errNo: Int)(implicit ctx: Context)
9393
extends Message(errNo) {
9494
val explanation = {
9595
val tryString = tryBody match {
@@ -121,23 +121,23 @@ object messages {
121121
}
122122

123123
case class EmptyCatchBlock(tryBody: untpd.Tree)(implicit ctx: Context)
124-
extends EmptyCatchOrFinallyBlock(tryBody, "E001") {
124+
extends EmptyCatchOrFinallyBlock(tryBody, 1) {
125125
val kind = "Syntax"
126126
val msg =
127127
hl"""|The ${"catch"} block does not contain a valid expression, try
128128
|adding a case like - `${"case e: Exception =>"}` to the block""".stripMargin
129129
}
130130

131131
case class EmptyCatchAndFinallyBlock(tryBody: untpd.Tree)(implicit ctx: Context)
132-
extends EmptyCatchOrFinallyBlock(tryBody, "E002") {
132+
extends EmptyCatchOrFinallyBlock(tryBody, 2) {
133133
val kind = "Syntax"
134134
val msg =
135135
hl"""|A ${"try"} without ${"catch"} or ${"finally"} is equivalent to putting
136136
|its body in a block; no exceptions are handled.""".stripMargin
137137
}
138138

139139
case class DeprecatedWithOperator()(implicit ctx: Context)
140-
extends Message("E003") {
140+
extends Message(3) {
141141
val kind = "Syntax"
142142
val msg =
143143
hl"""${"with"} as a type operator has been deprecated; use `&' instead"""
@@ -168,7 +168,7 @@ object messages {
168168

169169
// Type Errors ------------------------------------------------------------ //
170170
case class DuplicateBind(bind: untpd.Bind, tree: untpd.CaseDef)(implicit ctx: Context)
171-
extends Message("E004") {
171+
extends Message(4) {
172172
val kind = "Naming"
173173
val msg = em"duplicate pattern variable: `${bind.name}`"
174174

@@ -195,7 +195,7 @@ object messages {
195195
}
196196

197197
case class MissingIdent(tree: untpd.Ident, treeKind: String, name: String)(implicit ctx: Context)
198-
extends Message("E005") {
198+
extends Message(5) {
199199
val kind = "Missing Identifier"
200200
val msg = em"not found: $treeKind$name"
201201

@@ -206,7 +206,7 @@ object messages {
206206
}
207207

208208
case class TypeMismatch(found: Type, expected: Type, whyNoMatch: String = "", implicitFailure: String = "")(implicit ctx: Context)
209-
extends Message("E006") {
209+
extends Message(6) {
210210
val kind = "Type Mismatch"
211211
private val (where, printCtx) = Formatting.disambiguateTypes(found, expected)
212212
private val (fnd, exp) = Formatting.typeDiff(found, expected)(printCtx)

0 commit comments

Comments
 (0)