-
Notifications
You must be signed in to change notification settings - Fork 149
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
Enum families and overlapping enums #296
Comments
The current working behaviour, search within the scope of the If indeed, you require looking outside the scope of the enclosing |
I'm fine with saying this is working as intended. But note that the case objects in my example are still nested in an enclosing object. It's not impossible to find them without using Other than that should there be a warning or something when |
Another option would be to expose a |
In your original post, you stated that your issue was that
Your sealed trait Bar extends Foo
object Bar extends Enum[Bar] {
val values = findValues
} There are no
Last I checked Shapeless conjures its In any case, you can get what you want by doing something like this: import enumeratum._
sealed trait Foo extends EnumEntry
object Foo extends Enum[Foo] {
val values = findValues
case object Foo1 extends Foo
case object Foo2 extends Foo
case object Bar1 extends Bar
case object Bar2 extends Bar
case object Qux1 extends Qux
case object Qux2 extends Qux
case object BarQux1 extends Bar with Qux
case object BarQux2 extends Bar with Qux
sealed trait Bar extends Foo
object Bar extends Enum[Bar] {
val values = Foo.values.collect { case e: Bar => e }
}
sealed trait Qux extends Foo
object Qux extends Enum[Qux] {
val values = Foo.values.collect { case e: Qux => e }
}
}
println(Foo.values)
println(Foo.Bar.values)
println(Foo.Qux.values) Scastie: https://scastie.scala-lang.org/Adc4z1d3TXCh3UOhz4CM1A |
That's a really nice way to make it work and no need for shapeless. Thank you 👍 |
This works:
What I want:
Now that compiles, but at runtime
Bar.values
andQux.values
are empty!Work around with Shapeless:
The text was updated successfully, but these errors were encountered: