lloydmeta / enumeratum

A type-safe, reflection-free, powerful enumeration implementation for Scala with exhaustive pattern match warnings and helpful integrations.
MIT License
1.19k stars 148 forks source link

Members of enums nested in a class are not discovered in scala 3 #384

Open mrdziuban opened 10 months ago

mrdziuban commented 10 months ago

In this example case object a is discovered by findValues on scala 2, but is not on scala 3

https://scastie.scala-lang.org/mrdziuban/UeKyIrUZTi2ulDq9U89lmw/5

import enumeratum.{Enum, EnumEntry}

class Test() {
  sealed trait Foo extends EnumEntry
  object Foo extends Enum[Foo] {
    lazy val values = findValues
    case object a extends Foo
  }
}

val test = new Test()
test.Foo.values // Vector(): scala.collection.immutable.IndexedSeq[test.Foo]
lloydmeta commented 10 months ago

I'm actually surprised that nesting enums inside a class this is even a thing, as it brings to mind the question of things like whether the enum is owned by each instance of a class or whether it's "static". EDIT for clarity: should (new Test).Foo.a == (new Test).Foo.a???

In any case, I'm open to considering this something to "fix" for the sake of BWC with Scala 2, but also open to saying "no" to this and adding, say, a compiler warning for this kind of situation.