-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
There was a problem hiding this 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! ☀️
45bedcf
to
bfb719d
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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" | |||
} | |||
|
|||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
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.
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). |
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. |
You can make the tests pass by rebasing on top of master |
cdb25d6
to
0b934ce
Compare
| 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 |
There was a problem hiding this comment.
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""" |
There was a problem hiding this comment.
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 |
529943a
to
64c1797
Compare
64c1797
to
fe21e42
Compare
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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. | ||
""" |
There was a problem hiding this comment.
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."""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's take that.
There was a problem hiding this 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! 🎉
see #1589