Skip to content

Commit

Permalink
Fix support for ADT with unused type parameters (#554)
Browse files Browse the repository at this point in the history
* Fix support for ADT with unused type parameters

* Fix support for ADT with unused type parameters

Run fmt/fix

---------

Co-authored-by: Daniel Vigovszky <daniel.vigovszky@gmail.com>
  • Loading branch information
andrzejressel and vigoo authored Nov 18, 2023
1 parent 02ed1a7 commit 8a1561e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ object DeriveSchema {
val getArg = TermName(fieldLabel)

val getFunc = q" (z: $tpe) => z.$getArg"
val setFunc = q" (z: $tpe, v: ${fieldType}) => z.copy($getArg = v)"
val setFunc = q" (z: $tpe, v: $fieldType) => z.copy[..${tpe.typeArgs}]($getArg = v)"

if (annotations.nonEmpty) {
val newName = getFieldName(annotations).getOrElse(fieldLabel)
Expand All @@ -404,9 +404,9 @@ object DeriveSchema {

val constructExpr =
if (arity < 2)
q"defaultConstruct0 = (..$constructArgs) => $tpeCompanion(..$constructApplyArgs)"
q"defaultConstruct0 = (..$constructArgs) => $tpeCompanion[..${tpe.typeArgs}](..$constructApplyArgs)"
else
q"construct0 = (..$constructArgs) => $tpeCompanion(..$constructApplyArgs)"
q"construct0 = (..$constructArgs) => $tpeCompanion[..${tpe.typeArgs}](..$constructApplyArgs)"

val applyArgs =
if (typeAnnotations.isEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ object DeriveSchemaSpec extends ZIOSpecDefault with VersionSpecificDeriveSchemaS
case class BLeaf[B](value: B) extends RBTree[Nothing, B]
}

sealed trait AdtWithTypeParameters[+Param1, +Param2]

object AdtWithTypeParameters {
case class A[Param1, Param2](fieldWithParam1: Param1) extends AdtWithTypeParameters[Param1, Param2]
case class B[Param1, Param2](fieldWithParam2: Param2) extends AdtWithTypeParameters[Param1, Param2]
}
@annotation1("enum") sealed trait AnnotatedEnum

object AnnotatedEnum {
Expand Down Expand Up @@ -398,6 +404,10 @@ object DeriveSchemaSpec extends ZIOSpecDefault with VersionSpecificDeriveSchemaS
val derived: Schema[RBTree[String, Int]] = DeriveSchema.gen[RBTree[String, Int]]
assert(derived)(anything)
},
test("correctly derives schema with unused type parameters") {
val derived: Schema[AdtWithTypeParameters[Int, Int]] = DeriveSchema.gen[AdtWithTypeParameters[Int, Int]]
assert(derived)(anything)
},
test("correctly derives recursive Enum") {
assert(Schema[RecursiveEnum].toString)(not(containsString("null")) && not(equalTo("$Lazy$")))
},
Expand Down

0 comments on commit 8a1561e

Please sign in to comment.