-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #7499: Prevent extending java.lang.Enum except from an enum #9487
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 #7499: Prevent extending java.lang.Enum except from an enum #9487
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.
Thanks for taking this on 💯 I just have a few comments
ea212f2
to
72d9322
Compare
It's now possible to have a class that extends java.lang.Enum under |
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, thanks :)
@TheElectronWill sorry, I made a mistake by suggesting Traits should be able to extend trait T extends java.lang.Enum[T]
enum MyEnum extends T {
case A, B
} something like EnumSet becomes unusable due to the F bound: scala> java.util.EnumSet.allOf(classOf[MyEnum])
1 |java.util.EnumSet.allOf(classOf[MyEnum])
| ^^^^^^^^^^^^^^^
| Found: (classOf[MyEnum] : Class[MyEnum])
| Required: Class[E]
|
| where: E is a type variable with constraint <: Enum[LazyRef(E)] |
Ah! It's easy to forbid traits again, I'll make a PR right now. |
With this PR, extending
java.lang.Enum
from a class or trait gives an error.(one of) The Scala2 way(s) of declaring a java-compatible enum is also covered:
To emit a nice error for the above case I made the two-arguments constructor of
Enum
visible (if there's a better way I'll be glad to change that), and I introduced a check inCompleteJavaEnums
to prevent that constructor from being explicitely called.