Skip to content

Regression: Value enum entry type parameters can no longer be inferred #449

@jadenPete

Description

@jadenPete

Previously, value enum entry type parameters could be inferred:

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("Entry1")
  case object Entry2 extends ExampleEnumEntry("Entry2")

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

However, after #437 was merged, this now results in an error:

[info]   - should compile when entry type parameters are inferred *** FAILED ***
[info]     Expected no compiler error, but got the following type error: "
[info]     It looks like not all of the members have a literal/constant 'value:String' declaration, namely: object Entry1, object Entry2.
[info]     
[info]     This can happen if:
[info]     
[info]     - The aforementioned members have their `value` supplied by a variable, or otherwise defined as a method
[info]     
[info]     If none of the above apply to your case, it's likely you have discovered an issue with Enumeratum, so please file an issue :)
[info]              ", for code: 
[info]             sealed abstract class ExampleEnumEntry[Suffix](override val value: String) extends StringEnumEntry {
[info]               def toString(suffix: Suffix): String = value + suffix.toString
[info]             }
[info]     
[info]             object ExampleEnum extends StringEnum[ExampleEnumEntry[?]] {
[info]               case object Entry1 extends ExampleEnumEntry("Entry1")
[info]               case object Entry2 extends ExampleEnumEntry("Entry2")
[info]     
[info]               override def values: IndexedSeq[ExampleEnumEntry[?]] = findValues
[info]             } (ValueEnumSpec.scala:210)

This is a bit of a contrived example, because Suffix isn't inferred to be anything useful (I think it's inferred as Nothing), but I can demonstrate that this causes useful code to not compile.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions