Skip to content

Commit

Permalink
Fix deriving schema for generic types on scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse-Bakker committed Jul 31, 2023
1 parent 1b48895 commit 85d4fd4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ private case class DeriveSchema()(using val ctx: Quotes) extends ReflectionUtils
case Some(ref) =>
'{ Schema.defer(${ref.asExprOf[Schema[T]]}) }
case None =>
val summoned = if (!top) Expr.summon[Schema[T]] else None
summoned.map( s => '{ Schema.defer(${s}) }).getOrElse(
typeRepr.asType match {
case '[List[a]] =>
val schema = deriveSchema[a](stack)
Expand All @@ -77,14 +79,6 @@ private case class DeriveSchema()(using val ctx: Quotes) extends ReflectionUtils
val schema = deriveSchema[a](stack)
'{ Schema.chunk(Schema.defer(${schema})) }.asExprOf[Schema[T]]
case _ =>
val summoned = if (!top) Expr.summon[Schema[T]] else None
summoned match {
case Some(schema) =>
// println(s"FOR TYPE ${typeRepr.show}")
// println(s"STACK ${stack.find(typeRepr)}")
// println(s"Found schema ${schema.show}")
schema
case _ =>
Mirror(typeRepr) match {
case Some(mirror) =>
mirror.mirrorType match {
Expand All @@ -102,8 +96,8 @@ private case class DeriveSchema()(using val ctx: Quotes) extends ReflectionUtils
report.errorAndAbort(s"Deriving schema for ${typeRepr.show} is not supported")
}
}
}
}
)
}

//println()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ object DeriveSchemaSpec extends ZIOSpecDefault with VersionSpecificDeriveSchemaS
implicit lazy val schema: Schema[Recursive] = DeriveSchema.gen[Recursive]
}

case class GenericType[T](t: T)

object GenericType {
implicit def schema[T: Schema]: Schema[GenericType[T]] = DeriveSchema.gen[GenericType[T]]
}

case class Cyclic(field1: Long, child: CyclicChild1)

object Cyclic {
Expand Down

0 comments on commit 85d4fd4

Please sign in to comment.