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 2 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 == ErrorKind.NO_KIND) diagnosticLevel
else s"${message.kind} $diagnosticLevel"
val prefix = s"-- ${errId}${kind}: $file "

Expand Down
28 changes: 28 additions & 0 deletions compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorKind.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dotty.tools.dotc.reporting.diagnostic;

public enum ErrorKind {
Copy link
Contributor

@nicolasstucki nicolasstucki Jan 10, 2018

Choose a reason for hiding this comment

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

It would be better to have this in Scala.

class ErrorKind(name: String) {
  def toString(): String = name
}
object ErrorKinds {
  val NO_KIND = new ErrorKind("") 

  val COMPATIBILITY = new ErrorKind("Compatibility")
  val DEFINITION_NOT_FOUND = new ErrorKind("Definition Not Found")
  ...
}

Copy link
Contributor

Choose a reason for hiding this comment

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

We are already using java enums for ErrorMessageID. I think it is fine to stick to java enum until we migrate everything to Dotty enum.

I would however use Scala naming convention: NoKind instead of NO_KIND

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok.

But move NoKind to the first position.


COMPATIBILITY("Compatibility"),
DEFINITION_NOT_FOUND("Definition Not Found"),
DUPLICATE_SYMBOL("Duplicate Symbol"),
MATCH_CASE_UNREACHABLE("Match case Unreachable"),
MEMBER_NOT_FOUND("Member Not Found"),
NAMING("Naming"),
NO_KIND(""),
PATTERN_MATCH_EXHAUSTIVITY("Pattern Match Exhaustivity"),
REFERENCE("Reference"),
SYNTAX("Syntax"),
TYPE_MISMATCH("Type Mismatch"),
UNBOUND_IDENTIFIER("Unbound Identifier"),
USAGE("Usage");

private String repr;
ErrorKind(String repr) {
this.repr = repr;
}

@Override
public String toString() {
return repr;
}
}
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: ErrorKind

/** 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 = ErrorKind.NO_KIND
Copy link
Contributor

@nicolasstucki nicolasstucki Jan 10, 2018

Choose a reason for hiding this comment

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

With the change I proposed, this should become val kind = NO_KIND


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