@@ -1655,7 +1655,7 @@ object JsonCodecMaker {
1655
1655
discriminator : Option [ReadDiscriminator ],
1656
1656
in : Expr [JsonReader ],
1657
1657
default : Expr [A ],
1658
- ): Expr [A ] = {
1658
+ )( using Quotes ) : Expr [A ] = {
1659
1659
val tpe = types.head
1660
1660
val classInfo = getClassInfo(tpe)
1661
1661
checkFieldNameCollisions(tpe, cfg.discriminatorFieldName.fold(Seq .empty[String ]) { n =>
@@ -1678,11 +1678,12 @@ object JsonCodecMaker {
1678
1678
val rhs = Literal (IntConstant (if (i == lastParamVarIndex) lastParamVarBits else - 1 ))
1679
1679
ValDef (sym, Some (rhs))
1680
1680
}
1681
- val checkAndResetFieldPresenceFlags : Map [String , Expr [Int ] => Expr [Unit ]] = {
1681
+
1682
+ val checkAndResetFieldPresenceFlags : Map [String , Quotes ?=> Expr [Int ] => Expr [Unit ]] = {
1682
1683
classInfo.fields.zipWithIndex.map { case (f, i) =>
1683
1684
val n = Ref (paramVars(i >> 5 ).symbol).asExprOf[Int ]
1684
1685
val m = Expr (1 << i)
1685
- (f.mappedName, (l: Expr [Int ]) => ' {
1686
+ (f.mappedName, (q : Quotes ) ?=> ( l: Expr [Int ]) => ' {
1686
1687
if (($n & $m) != 0 )
1687
1688
$ {Assign (n.asTerm , ' { $n ^ $m }.asTerm).asExprOf[Unit ]}
1688
1689
else
@@ -1776,16 +1777,16 @@ object JsonCodecMaker {
1776
1777
val optDiscriminatorVar = discriminator.map{ _.valDef }
1777
1778
1778
1779
1779
- def blockWithVars (next : Term ) : Term =
1780
+ def blockWithVars [ A : Type ] (next : Expr [ A ])( using Quotes ) : Expr [ A ] =
1780
1781
Block (
1781
1782
readVars.toList ++
1782
1783
paramVars.toList ++
1783
1784
optDiscriminatorVar.toList,
1784
- next
1785
- )
1785
+ next.asTerm
1786
+ ).asExprOf[ A ]
1786
1787
1787
1788
' { if ($in.isNextToken('{' )) {
1788
- $ {blockWithVars(
1789
+ $ {blockWithVars[ A ] (
1789
1790
' {if (! $in.isNextToken('}' )) {
1790
1791
$in.rollbackToken()
1791
1792
var l = - 1
@@ -1796,7 +1797,7 @@ object JsonCodecMaker {
1796
1797
if (! $in.isCurrentToken('}' )) $in.objectEndOrCommaError()
1797
1798
}
1798
1799
$ {Block (checkReqVars.map(_.asTerm), construct).asExprOf[A ]}
1799
- }.asTerm ).asExprOf[A ]
1800
+ }).asExprOf[A ]
1800
1801
}
1801
1802
} else $in.readNullOrTokenError($default, '{' )
1802
1803
}
@@ -1878,7 +1879,7 @@ object JsonCodecMaker {
1878
1879
isStringified : Boolean ,
1879
1880
optDiscriminator : Option [ReadDiscriminator ],
1880
1881
in : Expr [JsonReader ]
1881
- ): Expr [C ] = {
1882
+ )( using Quotes ) : Expr [C ] = {
1882
1883
val tpe = types.head
1883
1884
val implCodec = findImplicitValueCodec(types)
1884
1885
val methodKey = DecoderMethodKey (tpe, isStringified && (isCollection(tpe) || isOption(tpe)), optDiscriminator.isDefined)
@@ -2943,12 +2944,17 @@ object JsonCodecMaker {
2943
2944
2944
2945
val codec = rootTpe.asType match {
2945
2946
case ' [rootType] =>
2946
- val codecExpr = ' {
2947
+ def codecExpr ( using Quotes ) = ' {
2947
2948
new JsonValueCodec [rootType] {
2948
2949
def nullValue : rootType = $ {genNullValue[rootType](rootTpe :: Nil )}
2949
2950
2950
2951
def decodeValue (in : JsonReader , default : rootType): rootType = {
2951
- $ {genReadVal(rootTpe :: Nil , ' default , cfg.isStringified, None , ' in )}
2952
+ $ {genReadVal(
2953
+ rootTpe :: Nil ,
2954
+ ' default ,
2955
+ cfg.isStringified,
2956
+ None ,
2957
+ ' in )}
2952
2958
}
2953
2959
2954
2960
def encodeValue (x : rootType, out : JsonWriter ): Unit = {
@@ -2957,6 +2963,7 @@ object JsonCodecMaker {
2957
2963
2958
2964
}
2959
2965
}
2966
+
2960
2967
val needDefs : List [Statement ] = (decodeMethodDefs.values.toList: List [Statement ]) ++
2961
2968
(encodeMethodDefs.values.toList: List [Statement ]) ++
2962
2969
(fieldIndexAccessors.values.toList: List [Statement ]) ++
0 commit comments