Skip to content
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

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

Closed
wants to merge 5 commits into from

Conversation

aesteve
Copy link
Contributor

@aesteve aesteve commented Jan 10, 2018

First step to give newcomers a better view of the different kind of errors the compiler may throw.

Having a quick glimpse at existing error kinds should help picking the right one (or adding a new one).

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

@@ -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.

@@ -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

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

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

Change the Java enum

@nicolasstucki
Copy link
Contributor

Otherwise it looks good

@aesteve
Copy link
Contributor Author

aesteve commented Jan 10, 2018

Ok thanks, I wasn't sure about the Java enum vs. Scala object vs. the new enum system coming. I read the full discussion on #1970 and I guess it ended up confusing me ^^

I changed it.

@@ -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

@aesteve
Copy link
Contributor Author

aesteve commented Jan 11, 2018

That should be OK now.

@aesteve
Copy link
Contributor Author

aesteve commented Jan 14, 2018

@allanrenucci is it OK for you now ?

The longer this PR is opened, the more conflicts with people implementing new error messages we may get :)

Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

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

LGTM. Please rebase

@aesteve
Copy link
Contributor Author

aesteve commented Jan 16, 2018

Sorry I must have messed up with the merge...

I have a lot of compiler errors now.

@allanrenucci
Copy link
Contributor

You can reopen a new PR if you feel like it is easier

@odersky
Copy link
Contributor

odersky commented Jan 12, 2019

Let's revisit using Dotty enums once we have the bootstrap (hopefully real soon now!)

@aesteve
Copy link
Contributor Author

aesteve commented Jan 12, 2019

Good, and thanks.
Please ping me once the bootstrap thing ( ? :\ ) is merged.
I'll then take my PR back (sorry for abandoning it), review/rewrite it then submit a new one.
Thanks for the work on dotty.

@OlivierBlanvillain
Copy link
Contributor

Please ping me once the bootstrap thing ( ? :\ ) is merged.

ping @aesteve

@aesteve
Copy link
Contributor Author

aesteve commented Jun 27, 2019

I'm giving it a try with a proper Scala enum here but tests are failing with failed: java.lang.NoSuchFieldError: NoKind, still need to figure out why :)

@b-studios
Copy link
Contributor

@aesteve Is this PR still active, or do you want to close it?

@aesteve
Copy link
Contributor Author

aesteve commented Apr 27, 2021

Hello and sorry.
Let's just close it. I still have this contribution in mind, but it would be better to restart from scratch.
Fortunately closing it doesn't mean it'll disappear I'll still have the diff as inspiration if I have time to rework it.

Sorry once again, never found the actual time to do this properly.

@b-studios
Copy link
Contributor

Don't worry -- thanks for your quick feedback.

@b-studios b-studios closed this Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants