Skip to content

Scala3 enum support #63

@jtjeferreira

Description

@jtjeferreira

Hi!

First of all, thanks for this nice library!

I was trying to use it with an enum like this:

import decisions4s.*

enum Foo {
  case Bar, Baz
}
object Foo {
  //Does not compile if commented
  implicit val literalShow: LiteralShow[Foo] = _.toString
}

case class Input[F[_]](
    numOfApprovals: F[Int],
    isTargetBranchProtected: F[Boolean],
    authorIsAdmin: F[Boolean],
    foo: F[Foo]
) derives HKD

case class Output[F[_]](
    allowMerging: F[Boolean],
    notifyUnusualAction: F[Boolean],
) derives HKD

def rules: List[Rule[Input, Output]] = List(
  // Unprotected branch requires 1 approval
  Rule(
    matching = Input(
      numOfApprovals = it > 0,
      isTargetBranchProtected = it.isFalse,
      authorIsAdmin = it.catchAll,
      foo = it.equalsTo(Foo.Bar),
    ),
    output = Output(allowMerging = true, notifyUnusualAction = false),
  ),
  // Nothing can be merged otherwise
  Rule.default(
    Output(allowMerging = false, notifyUnusualAction = false),
  ),
)

but I get an error

No given instance of type decisions4s.LiteralShow[Playground.Foo] was found for parameter x$2 of method equalsTo in object it.
I found:

    decisions4s.LiteralShow.product[T](
      shapeless3.deriving.K0.mkProductInstances[decisions4s.LiteralShow, T](
        /* missing */summon[scala.deriving².Mirror.Product of T]),
    ???)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions