-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix #9873: no longer use scala.Enum as parents of enums #9877
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 #9873: no longer use scala.Enum as parents of enums #9877
Conversation
…nums this commit introduces the concept that some desugaring expansion can occur after parents of the current class are known, i.e. methods that contain no references like ordinal and enumLabel.
77a53cf
to
2351587
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.
I don’t have enough expertise to review the implementation but the test enum-mirror-sumOf.scala looks good to me!
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.
This looks good to me, but it would be good to have confirmation from someone from the core dotty team on whether the new untpd
tree is the right way to go.
dca2f45
to
489a1af
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.
I think we should try to simplify this and reduce the scope. Let's discuss and possibly implement enumLabels
separately. For dropping scala.Enum, the approach looks good, but I think it can be simplified.
no longer special case some definitions for indexing after the parents of a class are discovered. Extend invalidateIfClashingSynthetic to cover ordinal override from java.lang.Enum
9c341f4
to
4e3d6e4
Compare
@odersky I have revisited the implementation so that the only special case is to add |
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.
Looks all good now, except for the suggested small change in SyntheticMembers.
Not really sure why the definitions are disappearing in the |
so it looks like calling Edit: apparently |
I think it's better not to remove ordinal. That's very tricky code, and we should use that only when absolutely necessary. As an alternative we could simply change the rhs of ordinal methods for cases of enums that extend java.lang Enum like this: override def ordinal: Int = super.ordinal I believe that's much easier to do. We could do this in SyntheticMethods, for instance, or anywhere else before RefChecks. |
Im not sure I understand, ordinal is a final method so we can't override it |
d977a03
to
be11253
Compare
@odersky In addition to invalidation I also now do not enter the symbol for ordinal until after typing the parents - but the logic is all localised to the indexExpanded method, but this is far more minimal then running the whole index function after parents (as I did with the EnumGetters magic) |
Ah. I did not consider that. Yes, scratch that idea then. |
This is quite a heroic effort from @bishabosha's part. It needs some tricky logic in Namer which is already a class that is pushing the complexity budget. But I wonder whether it's worth it. Is it not simpler to just keep the Enum trait? If we are concerned about naming it could be |
I think it could be a valuable for a reflection framework to know that a class or value is an enum case. So having |
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.
My current preference is to rename scala.Enum
to scala.runtime.Enum
and otherwise keep things as they are. I believe that's overall simplest.
In fact it could also be Also, while we are at it, I believe the |
close in favour of #9942 |
fixes #9873
this also adds a new method tono longer does thisderiving.Mirror.Sum
to access the enumLabel generically.Also removes the old unused enum helper classes from the non-bootstrapped library