Closed
Description
This issue poses the question of do we remove this trait, but keep the same API for individual enum classes, e.g. the following would still work after the change:
Minimized example
enum Colour extends java.lang.Enum[Colour]:
case Red, Green, Blue
@main def Test =
println(Colour.Red.enumLabel)
println(Colour.Green.ordinal)
println(Colour.Blue.isInstanceOf[scala.Enum])
Output
Red
1
false
Points in Favour
- If we remove the trait, then there is less overhead in the library, and there is no need to fully qualify
java.lang.Enum
- we still have Mirror framework which can be used to extract the ordinal generically
Points Against
- currently in desugaring there is no way to determine in the statements of
abstract class Colour
if it derives fromjava.lang.Enum
(Edit: alternatively it is possible to special case some specific desugarings to occur after parents are known) - therefore we can not avoid defining abstract
def ordinal: Int
when the parent isjava.lang.Enum
, leading to override errors - Mirror framework does not have generic way to fetch
enumLabel
scala.Enum
could be renamed (and remain a parent) so thatjava.lang.Enum
parent does not need to be fully qualified
Considerations
- perhaps the
ordinal
method should be renamed to avoid clashes withjava.lang.Enum
- perhaps we generate no public
ordinal
instance method and advise to use theordinal
method on the companion object. (same forenumLabel
?) - perhaps revise Mirror framework to have a label method for
Mirror.Sum