Closed
Description
Compiler version
3.0.1
Minimized code
import scala.deriving.Mirror
import scala.compiletime._
trait Schema[T] {
def build: T
}
object Schema extends SchemaDerivation {
implicit lazy val int: Schema[Int] = ???
implicit def option[A](implicit ev: Schema[A]): Schema[Option[A]] = ???
}
trait SchemaDerivation {
inline def recurse[A <: Tuple]: List[Schema[Any]] =
inline erasedValue[A] match {
case _: (t *: ts) =>
val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
builder :: recurse[ts]
case _: EmptyTuple => Nil
}
inline def derived[A]: Schema[A] =
inline summonInline[Mirror.Of[A]] match {
case m: Mirror.SumOf[A] =>
lazy val subTypes = recurse[m.MirroredElemTypes]
new Schema[A] {
def build: A = ???
}
case m: Mirror.ProductOf[A] =>
lazy val fields = recurse[m.MirroredElemTypes]
new Schema[A] {
def build: A = ???
}
}
inline given gen[A]: Schema[A] = derived
}
case class H(i: Int)
case class G(h: H)
case class F(g: G)
case class E(f: Option[F])
case class D(e: E)
case class C(d: D)
case class B(c: C)
case class A(a: Option[A], b: B)
object TestApp {
@main def test = {
implicit lazy val typeSchema: Schema[A] = Schema.gen
}
}
Output
given instance gen is declared as erased, but is in fact used
method recurse is declared as erased, but is in fact used
Expectation
I got this error while upgrading caliban from 3.0.0 to 3.0.1 on some code that was previously compiling. It seems that it fails to derive a typeclass instance in the presence of recursion and nesting. If I reduce the nesting, it works. I managed to reproduce it with the smaller example above, but this code fails with 3.0.0 with a different error. Any idea what's going on?