-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Problem extending java.lang.Enum #7174
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
Comments
Edit: this was removed as it is not applicable to the problem. |
I also confirmed that the following code works fine just in Dotty, not Scala 2. import java.{lang => jl}
enum FromMapMode extends jl.Enum[FromMapMode]{
case KEYS_ARE_PATHS, KEYS_ARE_KEYS
} |
I’m sceptical if the name + ordinal constructor should be exposed in Scala as it’s not visible in Java either |
@bishabosha But this is code existing in the Scala wild as there are no such restrictions from Scala. |
A longer term solution is to provide duplicate |
Well I would just say for migration you would be required to use the built-in enum which would synthesise a super call to jl.Enum with the identifier of the constant, and later should be have semantically correct valueOf, values etc. without needing the scala library. |
So the current plan is to prevent user-written classes that extend java.lang.Enum like the example, and migrate to the enum construct, once java compatible enums are complete - So I believe that this is out of scope to fix this in the meantime. |
Well, I know we are trying to make Scala safer but since there was no good solution for I think this should be supported and could be dropped in the future so this is my objection to closing this issue. Most Scala 2 code should work with some changes or rewrites otherwise the migration to Scala 3 won't be very pleasant. Of course, this project could be the only one that needs this capability so only the future will tell. |
If needs be, we can preserve the previous behavior under |
Its definitely important now to enable the constructor as enums can't be written under |
minimized code
problem
Currently the compiler requires an alias or fully specified class name for
java.lang.Enum
and errors when compiling.expectation
Should compile and not require a fully specified class name.
The text was updated successfully, but these errors were encountered: