Skip to content

Commit 3e6534c

Browse files
committed
Fix missing support of ADTs that has case classes with multiple parameter lists
1 parent 1e1ea2f commit 3e6534c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

jsoniter-scala-macros/shared/src/main/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ object JsonCodecMaker {
10171017
val nudeSubtype = TypeIdent(sym).tpe
10181018
val tpeArgsFromChild = typeArgs(nudeSubtype.baseType(tpe.typeSymbol))
10191019
nudeSubtype.memberType(sym.primaryConstructor) match
1020-
case MethodType(_, _, resTp) => resTp
1020+
case MethodType(_, _, _) => nudeSubtype
10211021
case PolyType(names, bounds, resPolyTp) =>
10221022
val targs = typeArgs(tpe)
10231023
val tpBinding = resolveParentTypeArgs(sym, tpeArgsFromChild, targs, Map.empty)

jsoniter-scala-macros/shared/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMakerSpec.scala

+10
Original file line numberDiff line numberDiff line change
@@ -3037,6 +3037,16 @@ class JsonCodecMakerSpec extends VerifyingSpec {
30373037
verifySerDeser(make[MultiListOfArgs](CodecMakerConfig.withRequireDefaultFields(true).withTransientDefault(false)),
30383038
new MultiListOfArgs(1)(2)("VVV"), """{"i":1,"l":2,"s":"VVV"}""")
30393039
}
3040+
"generate codecs for ADTs that has case classes with multiple parameter lists in a primary constructor" in {
3041+
sealed trait ADT
3042+
3043+
case class Data1(i: Int)(val pos: Int) extends ADT
3044+
3045+
case class Data2(i: Int)(val pos: Int) extends ADT
3046+
3047+
verifySerDeser(make[List[ADT]], List(Data1(1)(11), Data2(2)(22)),
3048+
"""[{"type":"Data1","i":1,"pos":11},{"type":"Data2","i":2,"pos":22}]""")
3049+
}
30403050
"don't generate codecs for case classes with non public parameters of the primary constructor" in {
30413051
assert(intercept[TestFailedException](assertCompiles {
30423052
"""case class MultiListOfArgsWithNonPublicParam(i: Int)(l: Long)

0 commit comments

Comments
 (0)