Skip to content

Commit 8e2c271

Browse files
authored
Merge pull request #1986 from dotty-staging/error-messages-ids
Use enum for error messages IDs.
2 parents f3f1c46 + eff2e07 commit 8e2c271

File tree

5 files changed

+116
-56
lines changed

5 files changed

+116
-56
lines changed

compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package reporting
55
import core.Contexts.Context
66
import core.Decorators._
77
import printing.Highlighting.{Blue, Red}
8-
import diagnostic.{Message, MessageContainer, NoExplanation}
8+
import diagnostic.{ErrorMessageID, Message, MessageContainer, NoExplanation}
99
import diagnostic.messages._
1010
import util.SourcePosition
1111

@@ -95,9 +95,10 @@ trait MessageRendering {
9595
if (pos.exists) Blue({
9696
val file = pos.source.file.toString
9797
val errId =
98-
if (message.errorId != NoExplanation.ID)
99-
s"[E${"0" * (3 - message.errorId.toString.length) + message.errorId}] "
100-
else ""
98+
if (message.errorId ne ErrorMessageID.NoExplanationID) {
99+
val errorNumber = message.errorId.errorNumber()
100+
s"[E${"0" * (3 - errorNumber.toString.length) + errorNumber}] "
101+
} else ""
101102
val kind =
102103
if (message.kind == "") diagnosticLevel
103104
else s"${message.kind} $diagnosticLevel"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package dotty.tools.dotc.reporting.diagnostic;
2+
3+
/** Unique IDs identifying the messages */
4+
public enum ErrorMessageID {
5+
6+
// IMPORTANT: Add new IDs only at the end and never remove IDs
7+
8+
LazyErrorId, // // errorNumber: -2
9+
NoExplanationID, // errorNumber: -1
10+
11+
EmptyCatchOrFinallyBlockID, // errorNumber: 0
12+
EmptyCatchBlockID, // errorNumber: 1
13+
EmptyCatchAndFinallyBlockID, // errorNumber: 2
14+
DeprecatedWithOperatorID,
15+
CaseClassMissingParamListID,
16+
DuplicateBindID,
17+
MissingIdentID,
18+
TypeMismatchID,
19+
NotAMemberID,
20+
EarlyDefinitionsNotSupportedID,
21+
TopLevelImplicitClassID,
22+
ImplicitCaseClassID,
23+
ObjectMayNotHaveSelfTypeID,
24+
TupleTooLongID,
25+
RepeatedModifierID,
26+
InterpolatedStringErrorID,
27+
UnboundPlaceholderParameterID,
28+
IllegalStartSimpleExprID,
29+
MissingReturnTypeID,
30+
YieldOrDoExpectedInForComprehensionID,
31+
ProperDefinitionNotFoundID,
32+
ByNameParameterNotSupportedID,
33+
WrongNumberOfTypeArgsID,
34+
IllegalVariableInPatternAlternativeID,
35+
TypeParamsTypeExpectedID,
36+
IdentifierExpectedID,
37+
AuxConstructorNeedsNonImplicitParameterID,
38+
IncorrectRepeatedParameterSyntaxID,
39+
IllegalLiteralID,
40+
PatternMatchExhaustivityID,
41+
MatchCaseUnreachableID,
42+
SeqWildcardPatternPosID,
43+
IllegalStartOfSimplePatternID,
44+
PkgDuplicateSymbolID,
45+
ExistentialTypesNoLongerSupportedID,
46+
UnboundWildcardTypeID,
47+
DanglingThisInPathID,
48+
OverridesNothingID,
49+
OverridesNothingButNameExistsID,
50+
ForwardReferenceExtendsOverDefinitionID,
51+
ExpectedTokenButFoundID;
52+
53+
public int errorNumber() {
54+
return ordinal() - 2;
55+
}
56+
57+
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ object Message {
3030
* Instead use the `persist` method to create an instance that does not keep a
3131
* reference to these contexts.
3232
*
33-
* @param errorId a unique number identifying the message, this will later be
33+
* @param errorId a unique id identifying the message, this will later be
3434
* used to reference documentation online
3535
*/
36-
abstract class Message(val errorId: Int) { self =>
37-
import messages._
36+
abstract class Message(val errorId: ErrorMessageID) { self =>
3837

3938
/** The `msg` contains the diagnostic message e.g:
4039
*
@@ -116,7 +115,7 @@ class ExtendMessage(_msg: () => Message)(f: String => String) { self =>
116115
}
117116

118117
/** The fallback `Message` containing no explanation and having no `kind` */
119-
class NoExplanation(val msg: String) extends Message(NoExplanation.ID) {
118+
class NoExplanation(val msg: String) extends Message(ErrorMessageID.NoExplanationID) {
120119
val explanation = ""
121120
val kind = ""
122121

@@ -127,8 +126,6 @@ class NoExplanation(val msg: String) extends Message(NoExplanation.ID) {
127126
* lacks an explanation
128127
*/
129128
object NoExplanation {
130-
final val ID = -1
131-
132129
def unapply(m: Message): Option[Message] =
133130
if (m.explanation == "") Some(m)
134131
else None

0 commit comments

Comments
 (0)