-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 #9179: ensure enum values are singleton with serialisation #9532
fix #9179: ensure enum values are singleton with serialisation #9532
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! ❤️
Commit Messages
We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).
Please stick to these guidelines for commit messages:
- Separate subject from body with a blank line
- When fixing an issue, start your commit message with
Fix #<ISSUE-NBR>:
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line ("Add" instead of "Added")
- Wrap the body at 80 characters
- Use the body to explain what and why vs. how
adapted from https://chris.beams.io/posts/git-commit
Have an awesome day! ☀️
c00bb5d
to
c69caa2
Compare
c69caa2
to
4f0cdcc
Compare
I guess the issue now is that if someone has the wrong parents for their enum, then they get a cryptic error related to an object of the wrong type being passed to the EnumValues.register method, e.g.: scala> enum Tag[+T]:
| case Int extends AnyRef
|
2 | case Int extends AnyRef
| ^
| Found: ($anon.this : Object with runtime.EnumValue {...})
| Required: Tag[?] Edit: this can be overcome by a cast at the register call that will be eliminated and refchecks will sanity check for unsafe casts |
Can't we do something like: |
4f0cdcc
to
2fa3d79
Compare
for enum Foo[F[_]]:
case Bar extends AnyRef what's the best way to invent type arguments for Foo that are well formed? as an alternative which I don't really like, I am replacing the template body with an empty list if the parents are bad |
Nothing is poly-kinded so |
4e03c31
to
84de445
Compare
@smarter thank you for your suggestion about adding in the parent, it seems to not cause any knock on effects |
4f7004d
to
b077100
Compare
I was experimenting with removing the EnumValueSerializationProxy class and was filtering on the companion to look for the .values method, but because it is has no parameters its info is ExprType and so its signature is Signature.NotAMethod, should that be correct?, is filtering by signature not possible? (.values is guaranteed anyway where I am doing this check so not necessary) |
That's normal yes, and you can filter by |
5d7c3ab
to
b077100
Compare
b077100
to
93b9361
Compare
I added another case to prevent anonymous classes extending an enum if they were defined within a term called |
70d0d55
to
82ec024
Compare
…rialization proxy
an error is reported when an enum does not have a parent the missing enum class is then added as a parent with appropriate type arguments. The body of the enum implementation class will now always be typechecked
82ec024
to
0872aaf
Compare
rebased |
I'm thinking that adding scala> enum Foo[T] extends java.lang.Enum[Foo[_]] { case A extends Foo[Unit] }
// defined class Foo
scala> java.util.EnumSet.allOf(classOf[Foo[?]])
java.lang.ClassCastException: class rs$line$1$Foo not an enum
at java.util.EnumSet.noneOf(EnumSet.java:112)
at java.util.EnumSet.allOf(EnumSet.java:131)
at rs$line$2$.<init>(rs$line$2:1)
at rs$line$2$.<clinit>(rs$line$2)
at rs$line$2.res0(rs$line$2)
... and now: scala> java.util.EnumSet.allOf(classOf[Foo[?]])
val res0: java.util.EnumSet[Foo[?]] = [A] |
Agreed (the alternative bugfix would be to reject java.lang.Enum parents for parameterized enums) |
depends on #9524 for correct semanticsmergedfixes #9179
this also adds the values and valueOf methods to companions of enums parameterised by a type