lloydmeta / enumeratum

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

Scala 3: findValues fails to find entries extending types with type parameters #372

Closed jadenPete closed 11 months ago

jadenPete commented 11 months ago

In Scala 3, ValueEnum entries can't have type parameters. More specifically, if an instance of a ValueEnum entry extends a type with type parameters, findValues will emit an error similar to the following one.

Fails to check value entry ExampleEnum.Entry1 for enum ExampleEnumEntry[_ >: scala.Nothing <: scala.Any]

See the following example.

import enumeratum.values.{StringEnum, StringEnumEntry}

sealed abstract class ExampleEnumEntry[Suffix](override val value: String) extends StringEnumEntry {
    def toString(suffix: Suffix): String = value + suffix.toString
}

object ExampleEnum extends StringEnum[ExampleEnumEntry[?]] {
    case object Entry1 extends ExampleEnumEntry[Int]("Entry1")
    case object Entry2 extends ExampleEnumEntry[String]("Entry2")

    override def values: IndexedSeq[ExampleEnumEntry[?]] = findValues
}

https://scastie.scala-lang.org/YLsHXSb3RrGwsoA9IXJIkA

lloydmeta commented 11 months ago

Closed by https://github.com/lloydmeta/enumeratum/pull/373