Skip to content

Error message for enum case in non-enum class companion object #3197

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 8 commits into from
Oct 11, 2017

Conversation

esarbe
Copy link
Contributor

@esarbe esarbe commented Sep 27, 2017

see #1589

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! ☀️

@esarbe esarbe force-pushed the desugarenum-message branch from 45bedcf to bfb719d Compare September 28, 2017 07:44
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

Otherwise, LGTM.

@@ -6,6 +6,7 @@ import core._
import util.Positions._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._
import Decorators._
import dotty.tools.dotc.reporting.diagnostic.messages.EnumCaseDefinitionInNonEnumOwner
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we shorten this to just reporting.diagnostic.messages.EnumCaseDefinitionInNonEnumOwner?

@@ -1748,7 +1748,7 @@ object messages {
val explanation =
hl"you have to provide either ${"class"}, ${"trait"}, ${"object"}, or ${"enum"} definitions after qualifiers"
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Introduction of a trailing space?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uh, nice catch! Thanks.

val explanation = {

hl"""
| ${"case"} is only allowed at this place if the surrounding object is the companion object of an `enum class`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, is ${"case"} equivalent to case? I see similar uses above which I don't understand.

@allanrenucci
Copy link
Contributor

Before we get this in, I think we should discuss if it is a good idea or not to have links in the error messages (ref #3199).

@esarbe
Copy link
Contributor Author

esarbe commented Sep 29, 2017

I can remove the link to circumvent the discussion. I'm quite willing to come back and re-introduce the link if this should be outcome of the discussion.

@allanrenucci
Copy link
Contributor

You can make the tests pass by rebasing on top of master

@esarbe esarbe force-pushed the desugarenum-message branch 2 times, most recently from cdb25d6 to 0b934ce Compare September 29, 2017 17:23
@allanrenucci allanrenucci self-assigned this Oct 3, 2017
| If you wanted to create an enumeration make sure that the corresponding class has the `${"enum"}` keyword.
| Otherwise you might have forgotten `${"class"}` or `${"object"}` after this `${"case"}` here.
|
""".stripMargin
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to stripMargin the hl interpolator does it for you.

val msg = em"case not allowed here, since owner `${owner}` is not an `${"enum"}` object"
val explanation = {

hl"""
Copy link
Contributor

@allanrenucci allanrenucci Oct 3, 2017

Choose a reason for hiding this comment

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

Start your message here and remove the whitespaces after |

@esarbe esarbe force-pushed the desugarenum-message branch from 529943a to 64c1797 Compare October 11, 2017 16:15
@esarbe esarbe force-pushed the desugarenum-message branch from 64c1797 to fe21e42 Compare October 11, 2017 16:25
@esarbe
Copy link
Contributor Author

esarbe commented Oct 11, 2017

Thanks for spotting these! Should be better now.

case class EnumCaseDefinitionInNonEnumOwner(owner: Symbol)(implicit ctx: Context)
extends Message(EnumCaseDefinitionInNonEnumOwnerID) {
val kind = "Syntax"
val msg = em"case not allowed here, since owner `${owner}` is not an `${"enum"}` object"
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't backtick owner and enum

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be fixed

| `${"case"}` is only allowed at this place if the surrounding object is the companion object of an `${"enum"} ${"class"}`.
| If you wanted to create an enumeration make sure that the corresponding class has the `${"enum"}` keyword.
| Otherwise you might have forgotten `${"class"}` or `${"object"}` after this `${"case"}` here.
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer something like:

  val explanation =
    hl"""${"enum"} cases are only allowed within the companion ${"object"} of an ${"enum class"}.
        |If you want to create an ${"enum"} case, make sure the corresponding ${"enum class"} exists
        |and has the ${"enum"} keyword."""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's take that.

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. Thank you for your contribution! 🎉

@allanrenucci allanrenucci merged commit 4d39ba2 into scala:master Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants