Skip to content

Fix #3784 : add an enum for Error kind #3785

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

Closed
wants to merge 5 commits into from
Closed
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 @@ -6,12 +6,12 @@ import core.Contexts.Context
import core.Decorators._
import printing.Highlighting.{Blue, Red}
import printing.SyntaxHighlighting
import diagnostic.{ErrorMessageID, Message, MessageContainer, NoExplanation}
import diagnostic._
import diagnostic.messages._
import util.SourcePosition
import util.Chars.{ LF, CR, FF, SU }
import scala.annotation.switch
import util.Chars.{CR, FF, LF, SU}

import scala.annotation.switch
import scala.collection.mutable

trait MessageRendering {
Expand Down Expand Up @@ -117,7 +117,7 @@ trait MessageRendering {
s"[E${"0" * (3 - errorNumber.toString.length) + errorNumber}] "
} else ""
val kind =
if (message.kind == "") diagnosticLevel
if (message.kind == ErrorCategory.NoKind) diagnosticLevel
else s"${message.kind} $diagnosticLevel"
val prefix = s"-- ${errId}${kind}: $file "

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dotty.tools.dotc.reporting.diagnostic

sealed abstract class ErrorCategory(name: String) {
override def toString: String = name
}
object ErrorCategory {

val NoKind = new ErrorCategory("") {}

val Compatibility = new ErrorCategory("Compatibility") {}
val DefinitionNotFound = new ErrorCategory("Definition Not Found") {}
val DuplicateSymbol = new ErrorCategory("Duplicate Symbol") {}
val MatchCaseUnreachable = new ErrorCategory("Match case Unreachable") {}
val MemberNotFound = new ErrorCategory("Member Not Found") {}
val Naming = new ErrorCategory("Naming") {}
val PatternMatchExhaustivity = new ErrorCategory("Pattern Match Exhaustivity") {}
val Reference = new ErrorCategory("Reference") {}
val Syntax = new ErrorCategory("Syntax") {}
val TypeMismatch = new ErrorCategory("Type Mismatch") {}
val UnboundIdentifier = new ErrorCategory("Unbound Identifier") {}
val Usage = new ErrorCategory("Usage") {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class Message(val errorId: ErrorMessageID) { self =>
/** The kind of the error message is something like "Syntax" or "Type
* Mismatch"
*/
def kind: String
def kind: ErrorCategory

/** The explanation should provide a detailed description of why the error
* occurred and use examples from the user's own code to illustrate how to
Expand Down Expand Up @@ -117,7 +117,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(ErrorMessageID.NoExplanationID) {
val explanation = ""
val kind = ""
val kind = ErrorCategory.NoKind

override def toString(): String = s"NoExplanation($msg)"
}
Expand Down
Loading