generate type aliases for singleton enum values? #17861
davidabrahams
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
Recently I wanted to write code which looked liked this: https://scastie.scala-lang.org/FmYhh8FeQRigeVaW9O42YQ
I have an
enum
with three cases, and in one branch of logic I know certain cases are impossible, and I wanted to express that in the types. As far as I know the only way to do this is to directly refer to the.type
s of the singleton values. This leads to ugliness like:I was able to get around this by adding type aliases to the enum's companion: https://scastie.scala-lang.org/vevKe2erRD2jpT1fNN1YMA
This felt like something which dotty could potentially do behind the scenes when compiling enums? I'm not sure how feasible this is or if I'm missing something.
Beta Was this translation helpful? Give feedback.
All reactions