Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for ADT with unused type parameters #554

Merged
merged 6 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading