diff --git a/zio-schema-derivation/shared/src/main/scala-2/zio/schema/DeriveSchema.scala b/zio-schema-derivation/shared/src/main/scala-2/zio/schema/DeriveSchema.scala index aca1ba21e..78e8f5b0f 100644 --- a/zio-schema-derivation/shared/src/main/scala-2/zio/schema/DeriveSchema.scala +++ b/zio-schema-derivation/shared/src/main/scala-2/zio/schema/DeriveSchema.scala @@ -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) @@ -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) diff --git a/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala b/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala index 7b377c881..f179f90c8 100644 --- a/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala +++ b/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala @@ -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 { @@ -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$"))) },