@@ -974,16 +974,16 @@ object JsonCodecMaker {
974
974
isStringified : Boolean ,
975
975
nonTransientFieldIndex : Int )
976
976
977
- case class ClassInfo (tpe : TypeRepr , primaryConstructor : Symbol , paramLists : List [List [FieldInfo ]]) {
977
+ case class ClassInfo (tpe : TypeRepr , tpeTypeArgs : List [ TypeRepr ], primaryConstructor : Symbol , paramLists : List [List [FieldInfo ]]) {
978
978
val fields : List [FieldInfo ] = paramLists.flatten.filter(! _.isTransient)
979
979
980
980
def genNew (arg : Term ): Term = genNew(List (List (arg)))
981
981
982
982
def genNew (argss : List [List [Term ]]): Term =
983
983
val constructorNoTypes = Select (New (Inferred (tpe)), primaryConstructor)
984
- val constructor = typeArgs(tpe) match
985
- case Nil => constructorNoTypes
986
- case typeArgs => TypeApply (constructorNoTypes, typeArgs .map(Inferred (_)))
984
+ val constructor =
985
+ if (tpeTypeArgs.isEmpty) constructorNoTypes
986
+ else TypeApply (constructorNoTypes, tpeTypeArgs .map(Inferred (_)))
987
987
argss.tail.foldLeft(Apply (constructor, argss.head))((acc, args) => Apply (acc, args))
988
988
}
989
989
@@ -1002,6 +1002,7 @@ object JsonCodecMaker {
1002
1002
if (cfg.scalaTransientSupport) s " ' ${Type .show[transient]}' (or ' ${Type .show[scala.transient]}') "
1003
1003
else s " ' ${Type .show[transient]}') "
1004
1004
1005
+ val tpeTypeArgs = typeArgs(tpe)
1005
1006
val tpeClassSym = tpe.classSymbol.getOrElse(fail(s " Expected that ${tpe.show} has classSymbol " ))
1006
1007
var annotations = Map .empty[String , FieldAnnotations ]
1007
1008
tpeClassSym.fieldMembers.foreach {
@@ -1060,7 +1061,7 @@ object JsonCodecMaker {
1060
1061
val dvSelectNoTArgs = Ref (tpe.typeSymbol.companionModule).select(methodSymbol)
1061
1062
val dvSelect = methodSymbol.paramSymss match
1062
1063
case Nil => dvSelectNoTArgs
1063
- case List (params) if params.exists(_.isTypeParam) => typeArgs(tpe) match
1064
+ case List (params) if params.exists(_.isTypeParam) => tpeTypeArgs match
1064
1065
case Nil => fail(s " Expected that ${tpe.show} is an applied type " )
1065
1066
case typeArgs => TypeApply (dvSelectNoTArgs, typeArgs.map(Inferred (_)))
1066
1067
case paramss => fail(s " Default method for ${symbol.name} of class ${tpe.show} have a complex " +
@@ -1070,7 +1071,7 @@ object JsonCodecMaker {
1070
1071
val isStringified = annotationOption.exists(_.stringified)
1071
1072
val isTransient = annotationOption.exists(_.transient)
1072
1073
val originFieldType = tpe.memberType(symbol).dealias
1073
- val fieldType = typeArgs(tpe) match
1074
+ val fieldType = tpeTypeArgs match
1074
1075
case Nil => originFieldType
1075
1076
case typeArgs => originFieldType.substituteTypes(typeParams, typeArgs)
1076
1077
fieldType match
@@ -1094,7 +1095,7 @@ object JsonCodecMaker {
1094
1095
if (! isTransient) i += 1
1095
1096
i
1096
1097
}
1097
- ClassInfo (tpe, primaryConstructor, primaryConstructor.paramSymss match {
1098
+ ClassInfo (tpe, tpeTypeArgs, primaryConstructor, primaryConstructor.paramSymss match {
1098
1099
case tps :: pss if tps.exists(_.isTypeParam) => pss.map(ps => createFieldInfos(ps, tps, fieldIndex))
1099
1100
case pss => pss.map(ps => createFieldInfos(ps, Nil , fieldIndex))
1100
1101
})
@@ -1207,8 +1208,7 @@ object JsonCodecMaker {
1207
1208
else if (isValueClass(tpe)) {
1208
1209
val vtpe = valueClassValueType(tpe)
1209
1210
vtpe.asType match
1210
- case ' [vt] =>
1211
- getClassInfo(tpe).genNew(genReadKey[vt](vtpe :: types, in).asTerm).asExprOf[T ]
1211
+ case ' [vt] => getClassInfo(tpe).genNew(genReadKey[vt](vtpe :: types, in).asTerm).asExprOf[T ]
1212
1212
} else if (tpe =:= TypeRepr .of[BigInt ]) ' { $in.readKeyAsBigInt($ {Expr (cfg.bigIntDigitsLimit)}) }.asExprOf[T ]
1213
1213
else if (tpe =:= TypeRepr .of[BigDecimal ]) {
1214
1214
val mc = withMathContextFor(cfg.bigDecimalPrecision)
@@ -1552,7 +1552,7 @@ object JsonCodecMaker {
1552
1552
} else s " No implicit ' ${TypeRepr .of[JsonValueCodec [_]].show}' defined for ' ${tpe.show}'. " )
1553
1553
1554
1554
def namedValueOpt (namedAnnotation : Option [Term ], tpe : TypeRepr ): Option [String ] = namedAnnotation.map {
1555
- case Apply (_, List (param)) => CompileTimeEval .evalExpr(param.asExprOf[String ]).asTerm match // TODO: write testcase
1555
+ case Apply (_, List (param)) => CompileTimeEval .evalExpr(param.asExprOf[String ]).asTerm match
1556
1556
case Literal (StringConstant (s)) => s
1557
1557
case _ => fail(s " Cannot evaluate a parameter of the '@named' annotation in type ' ${tpe.show}': $param. " )
1558
1558
case a => fail(s " Invalid named annotation ${a.show}" )
@@ -1969,7 +1969,8 @@ object JsonCodecMaker {
1969
1969
else mappedNames
1970
1970
})
1971
1971
val required = fields.collect {
1972
- case fieldInfo if ! ((! cfg.requireDefaultFields && fieldInfo.symbol.flags.is(Flags .HasDefault )) || isOption(fieldInfo.resolvedTpe, types) || isNullable(fieldInfo.resolvedTpe) ||
1972
+ case fieldInfo if ! ((! cfg.requireDefaultFields && fieldInfo.symbol.flags.is(Flags .HasDefault )) ||
1973
+ isOption(fieldInfo.resolvedTpe, types) || isNullable(fieldInfo.resolvedTpe) ||
1973
1974
(! cfg.requireCollectionFields && isCollection(fieldInfo.resolvedTpe))) => fieldInfo.mappedName
1974
1975
}.toSet
1975
1976
val paramVarNum = fields.size
0 commit comments