Skip to content

Commit 8a1561e

Browse files
andrzejresselvigoo
andauthored
Fix support for ADT with unused type parameters (#554)
* 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>
1 parent 02ed1a7 commit 8a1561e

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

zio-schema-derivation/shared/src/main/scala-2/zio/schema/DeriveSchema.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ object DeriveSchema {
379379
val getArg = TermName(fieldLabel)
380380

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

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

405405
val constructExpr =
406406
if (arity < 2)
407-
q"defaultConstruct0 = (..$constructArgs) => $tpeCompanion(..$constructApplyArgs)"
407+
q"defaultConstruct0 = (..$constructArgs) => $tpeCompanion[..${tpe.typeArgs}](..$constructApplyArgs)"
408408
else
409-
q"construct0 = (..$constructArgs) => $tpeCompanion(..$constructApplyArgs)"
409+
q"construct0 = (..$constructArgs) => $tpeCompanion[..${tpe.typeArgs}](..$constructApplyArgs)"
410410

411411
val applyArgs =
412412
if (typeAnnotations.isEmpty)

zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ object DeriveSchemaSpec extends ZIOSpecDefault with VersionSpecificDeriveSchemaS
175175
case class BLeaf[B](value: B) extends RBTree[Nothing, B]
176176
}
177177

178+
sealed trait AdtWithTypeParameters[+Param1, +Param2]
179+
180+
object AdtWithTypeParameters {
181+
case class A[Param1, Param2](fieldWithParam1: Param1) extends AdtWithTypeParameters[Param1, Param2]
182+
case class B[Param1, Param2](fieldWithParam2: Param2) extends AdtWithTypeParameters[Param1, Param2]
183+
}
178184
@annotation1("enum") sealed trait AnnotatedEnum
179185

180186
object AnnotatedEnum {
@@ -398,6 +404,10 @@ object DeriveSchemaSpec extends ZIOSpecDefault with VersionSpecificDeriveSchemaS
398404
val derived: Schema[RBTree[String, Int]] = DeriveSchema.gen[RBTree[String, Int]]
399405
assert(derived)(anything)
400406
},
407+
test("correctly derives schema with unused type parameters") {
408+
val derived: Schema[AdtWithTypeParameters[Int, Int]] = DeriveSchema.gen[AdtWithTypeParameters[Int, Int]]
409+
assert(derived)(anything)
410+
},
401411
test("correctly derives recursive Enum") {
402412
assert(Schema[RecursiveEnum].toString)(not(containsString("null")) && not(equalTo("$Lazy$")))
403413
},

0 commit comments

Comments
 (0)