typelevel / kittens

Automatic type class derivation for Cats
Apache License 2.0
536 stars 64 forks source link

Scala 3 regression: derivation error for value classes #658

Open yakivy opened 6 months ago

yakivy commented 6 months ago
"org.typelevel" %% "kittens" % "3.3.0"
import cats.derived._
case class MyString(value: String) extends AnyVal
semiauto.monoid[MyString]

this snippet compiles successfully on Scala 2.13, but fails on Scala 3:

No given instance of type cats.derived.DerivedMonoid[Playground.MyString] was found.
I found:

    cats.derived.DerivedMonoid.given_DerivedMonoid_A[Playground.MyString](
      shapeless3.deriving.K0.mkProductInstances[
        [A] =>> cats.derived.Derived.Or[cats.kernel.Monoid[A]], Playground.MyString]
        (
        /* missing */
          summon[shapeless3.deriving.K0.ProductGeneric[Playground.MyString]]
      )
    )

But Failed to synthesize an instance of type shapeless3.deriving.K0.ProductGeneric[Playground.MyString]: class MyString is not a generic product because it is a value class.

The following import might make progress towards fixing the problem:

  import cats.derived.DerivedMonoid.Strict.product

Scastie: https://scastie.scala-lang.org/DqVORi3bSU6rB8JM0PupHw

joroKr21 commented 6 months ago

Interesting, that might be an issue with Shapeless 3 or even Scala 3

joroKr21 commented 6 months ago

Looks like Scala 3 behaviour


scala> summon[Mirror.Of[MyString]]
-- [E172] Type Error: ----------------------------------------------------------
1 |summon[Mirror.Of[MyString]]
  |                           ^
  |No given instance of type scala.deriving.Mirror.Of[MyString] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[MyString]:
  | * class MyString is not a generic product because it is a value class
  | * class MyString is not a generic sum because it is not a sealed class
1 error found
joroKr21 commented 6 months ago

Looks like people tried and it didn't work: https://github.com/scala/scala3/issues/7000