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 3 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 == ErrorCategories.NO_KIND) 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,20 @@
package dotty.tools.dotc.reporting.diagnostic

sealed case class ErrorCategory(name: String) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you intend to make it behave like an enum, I suggest you use this pattern:

sealed abstract class ErrorCategory(category: String) {
   ...
}
object ErrorCategory {
  val NoKind = new ErrorCategory("") {}
  ...
}

override def toString: String = name
}
object ErrorCategories {
val COMPATIBILITY = ErrorCategory("Compatibility")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Scala naming convention: NoKind instead of NO_KIND. Also I would put NoKind at the top.

Copy link
Contributor Author

@aesteve aesteve Jan 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can definitely rename everything, but it unfortunately clashes with the case class PatternMatchExhaustivity(uncovered: String) (both the message and kind clash together). What would you recommend ? Keep the same name but prefix like  val kind = ErrorCategory.PatternMatchExhaustivity or rename the enum members ? (if so, how ?). Thanks for your insights

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you can disambiguate with val kind = ErrorCategory.PatternMatchExhaustivity

val DEFINITION_NOT_FOUND = ErrorCategory("Definition Not Found")
val DUPLICATE_SYMBOL = ErrorCategory("Duplicate Symbol")
val MATCH_CASE_UNREACHABLE = ErrorCategory("Match case Unreachable")
val MEMBER_NOT_FOUND = ErrorCategory("Member Not Found")
val NAMING = ErrorCategory("Naming")
val NO_KIND = ErrorCategory("")
val PATTERN_MATCH_EXHAUSTIVITY = ErrorCategory("Pattern Match Exhaustivity")
val REFERENCE = ErrorCategory("Reference")
val SYNTAX = ErrorCategory("Syntax")
val TYPE_MISMATCH = ErrorCategory("Type Mismatch")
val UNBOUND_IDENTIFIER = ErrorCategory("Unbound Identifier")
val USAGE = 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 = ErrorCategories.NO_KIND

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