Skip to content
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

Multiple parameter lists on an Entry implementation can break the constant value check #318

Open
coreywoodfield opened this issue May 24, 2021 · 1 comment

Comments

@coreywoodfield
Copy link
Contributor

coreywoodfield commented May 24, 2021

Expected: ValueEnumEntry implementations compile if they have a literal value parameter.

Actual: ValueEnumEntry implementations with multiple parameter lists sometimes don't compile even when they have a literal value parameter

Example 1:

sealed abstract class Entry(val value: String)(blah: String) extends StringEnumEntry

object Enum extends StringEnum[Entry] {
  case object Test1 extends Entry("test1")("")
  case object Test2 extends Entry("test2")(Test1.value.toUpperCase())

  override def values: IndexedSeq[Entry] = findValues
}

results in It looks like not all of the members have a literal/constant 'value:String' declaration, namely: object Test2. even though Test2 has a constant value for value. Note that in this case Test1 works fine.

Example 2:

sealed abstract class Entry(blah: String)(val value: String) extends StringEnumEntry

object Enum extends StringEnum[Entry] {
  case object Test1 extends Entry("")("test1")
  case object Test2 extends Entry("")("test2")

  override def values: IndexedSeq[Entry] = findValues
}

results in It looks like not all of the members have a literal/constant 'value:String' declaration, namely: object Test1, object Test2. even though both objects have unique constant values for value, and no variables or methods anywhere.

Example 3:

sealed abstract class Entry(val value: String)(implicit blah: String) extends StringEnumEntry

object Enum extends StringEnum[Entry] {
  implicit val blah: String = ""

  case object Test1 extends Entry("test1")
  case object Test2 extends Entry("test2")(blah)

  override def values: IndexedSeq[Entry] = findValues
}

results in It looks like not all of the members have a literal/constant 'value:String' declaration, namely: object Test2. even though Test2 has a constant value for value. Note also that the definitions are equivalent after implicit resolution.

@lloydmeta
Copy link
Owner

Nice find :)

Looks like the check in the macro just needs to find a value: ValueType param among all param lists.

A PR would be welcome 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants