Skip to content

Use enum for error messages IDs. #1986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package reporting
import core.Contexts.Context
import core.Decorators._
import printing.Highlighting.{Blue, Red}
import diagnostic.{Message, MessageContainer, NoExplanation}
import diagnostic.{ErrorMessageID, Message, MessageContainer, NoExplanation}
import diagnostic.messages._
import util.SourcePosition

Expand Down Expand Up @@ -95,9 +95,10 @@ trait MessageRendering {
if (pos.exists) Blue({
val file = pos.source.file.toString
val errId =
if (message.errorId != NoExplanation.ID)
s"[E${"0" * (3 - message.errorId.toString.length) + message.errorId}] "
else ""
if (message.errorId ne ErrorMessageID.NoExplanationID) {
val errorNumber = message.errorId.errorNumber()
s"[E${"0" * (3 - errorNumber.toString.length) + errorNumber}] "
} else ""
val kind =
if (message.kind == "") diagnosticLevel
else s"${message.kind} $diagnosticLevel"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package dotty.tools.dotc.reporting.diagnostic;

/** Unique IDs identifying the messages */
public enum ErrorMessageID {

// IMPORTANT: Add new IDs only at the end and never remove IDs

LazyErrorId, // // errorNumber: -2
NoExplanationID, // errorNumber: -1

EmptyCatchOrFinallyBlockID, // errorNumber: 0
EmptyCatchBlockID, // errorNumber: 1
EmptyCatchAndFinallyBlockID, // errorNumber: 2
DeprecatedWithOperatorID,
CaseClassMissingParamListID,
DuplicateBindID,
MissingIdentID,
TypeMismatchID,
NotAMemberID,
EarlyDefinitionsNotSupportedID,
TopLevelImplicitClassID,
ImplicitCaseClassID,
ObjectMayNotHaveSelfTypeID,
TupleTooLongID,
RepeatedModifierID,
InterpolatedStringErrorID,
UnboundPlaceholderParameterID,
IllegalStartSimpleExprID,
MissingReturnTypeID,
YieldOrDoExpectedInForComprehensionID,
ProperDefinitionNotFoundID,
ByNameParameterNotSupportedID,
WrongNumberOfTypeArgsID,
IllegalVariableInPatternAlternativeID,
TypeParamsTypeExpectedID,
IdentifierExpectedID,
AuxConstructorNeedsNonImplicitParameterID,
IncorrectRepeatedParameterSyntaxID,
IllegalLiteralID,
PatternMatchExhaustivityID,
MatchCaseUnreachableID,
SeqWildcardPatternPosID,
IllegalStartOfSimplePatternID,
PkgDuplicateSymbolID,
ExistentialTypesNoLongerSupportedID,
UnboundWildcardTypeID,
DanglingThisInPathID,
OverridesNothingID,
OverridesNothingButNameExistsID,
ForwardReferenceExtendsOverDefinitionID,
ExpectedTokenButFoundID;

public int errorNumber() {
return ordinal() - 2;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ object Message {
* Instead use the `persist` method to create an instance that does not keep a
* reference to these contexts.
*
* @param errorId a unique number identifying the message, this will later be
* @param errorId a unique id identifying the message, this will later be
* used to reference documentation online
*/
abstract class Message(val errorId: Int) { self =>
import messages._
abstract class Message(val errorId: ErrorMessageID) { self =>

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

/** The fallback `Message` containing no explanation and having no `kind` */
class NoExplanation(val msg: String) extends Message(NoExplanation.ID) {
class NoExplanation(val msg: String) extends Message(ErrorMessageID.NoExplanationID) {
val explanation = ""
val kind = ""

Expand All @@ -127,8 +126,6 @@ class NoExplanation(val msg: String) extends Message(NoExplanation.ID) {
* lacks an explanation
*/
object NoExplanation {
final val ID = -1

def unapply(m: Message): Option[Message] =
if (m.explanation == "") Some(m)
else None
Expand Down
Loading