Finalising Enumerations for Scala 3

When an enum includes parameterized cases the values companion member is not generated (correctly, as it would need to include null elements). However the fromOrdinal member is generated, and is undefined at ordinals corresponding to parameterized cases. I find this surprising because fromOrdinal is not an inverse of ordinal in these cases (a roundabout way of saying it’s kind of weird to have fromOrdinal at all for such data types)

My initial suggestion was to generate fromOrdinal only in the same circumstances where values is generated; but it turns out readResolve for non-parameterized cases relies on fromOrdinal, so maybe we should make it private in this case?

4 Likes