-
Notifications
You must be signed in to change notification settings - Fork 152
Open
Labels
Description
Hi,
This is perhaps not a bug, technically, but I found the behavior suprising.
It seems that 'intermediate' abstract classes in a hierarchy must themselves be explicitly marked as sealed for findValues to pick them up.
Here's a little reproducer:
import enumeratum.*
sealed abstract class MyEnum(name: String) extends EnumEntry
object MyEnum extends Enum[MyEnum] {
abstract class Intermediate(name: String)
extends MyEnum(name = name)
case object Foo extends MyEnum("Foo")
case object Bar extends Intermediate("Bar")
val values: IndexedSeq[MyEnum] =
findValues
@main
def main(): Unit =
Console.println(s"values: $values")
}Will print
values: Vector(Foo)
instead of the expected
values: Vector(Bar, Foo)
Marking the Intermediate abstract class with sealed makes it show up.
Now, technically, the un-sealed abstract class could be extended by code elsewhere (and so all potential subclasses cannot be known), but I found this behavior of simply omitting the Bar very surprising... kind of dangerous because the omission is silent.
Could the macros be changed to include Bar (per the example), or maybe to emit a compiler warning/error about the missing 'sealed'?
lloydmeta