@@ -1426,7 +1426,8 @@ object JsonCodecMaker {
1426
1426
val fieldIndexAccessors = mutable.LinkedHashMap .empty[TypeRepr , DefDef ]
1427
1427
1428
1428
1429
- def withFieldsFor (tpe : TypeRepr )(f : => Seq [String ]): Expr [Int => String ] = {
1429
+ def withFieldsByIndexFor (tpe : TypeRepr )(f : => Seq [String ]): Term = {
1430
+ // [Int => String], we don't want eta-expand without reason, so let this will be just index.
1430
1431
val defDef = fieldIndexAccessors.getOrElseUpdate(tpe, {
1431
1432
val name = " f" + fieldIndexAccessors.size
1432
1433
val mt = MethodType (List (" i" ))(_ => List (TypeRepr .of[Int ]), _ => TypeRepr .of[String ] )
@@ -1442,7 +1443,7 @@ object JsonCodecMaker {
1442
1443
Some (body)
1443
1444
})
1444
1445
})
1445
- Ref (defDef.symbol).asExprOf[Int => String ]
1446
+ Ref (defDef.symbol)// .asExprOf[Int => String]
1446
1447
}
1447
1448
1448
1449
val equalsMethods = mutable.LinkedHashMap .empty[TypeRepr , DefDef ]
@@ -1693,7 +1694,7 @@ object JsonCodecMaker {
1693
1694
val checkReqVars =
1694
1695
if (required.isEmpty) Nil
1695
1696
else {
1696
- val names = withFieldsFor (tpe)(classInfo.fields.map(_.mappedName))
1697
+ val nameByIndex = withFieldsByIndexFor (tpe)(classInfo.fields.map(_.mappedName))
1697
1698
val reqMasks = classInfo.fields.grouped(32 ).toSeq.map(_.zipWithIndex.foldLeft(0 ) { case (acc, (f, i)) =>
1698
1699
if (required(f.mappedName)) acc | (1 << i)
1699
1700
else acc
@@ -1702,9 +1703,11 @@ object JsonCodecMaker {
1702
1703
val n = Ref (nValDef.symbol).asExprOf[Int ]
1703
1704
val m = Expr (reqMasks(i))
1704
1705
val fieldName =
1705
- if (i == 0 ) ' { $names(java.lang.Integer .numberOfTrailingZeros($n & $m)) }
1706
- else ' { $names(java.lang.Integer .numberOfTrailingZeros($n & $m) + $ {Expr (i << 5 )}) }
1707
- ' { if ( ($n & $m) != 0 ) $in.requiredFieldError($fieldName) }
1706
+ if (i == 0 )
1707
+ Apply (nameByIndex,List ( ' {java.lang.Integer .numberOfTrailingZeros($n & $m) }.asTerm) )
1708
+ else
1709
+ Apply (nameByIndex,List ( ' { java.lang.Integer .numberOfTrailingZeros($n & $m) + $ {Expr (i << 5 )} }.asTerm ))
1710
+ ' { if ( ($n & $m) != 0 ) $in.requiredFieldError($ {fieldName.asExprOf[String ]}) }
1708
1711
}.toList
1709
1712
}
1710
1713
val readVars : Seq [ValDef ] = classInfo.fields.map { f =>
@@ -1734,7 +1737,7 @@ object JsonCodecMaker {
1734
1737
else classInfo.fields :+ FieldInfo (Symbol .noSymbol, n, Symbol .noSymbol, None , TypeRepr .of[String ], isStringified = true )
1735
1738
}
1736
1739
1737
- def genReadCollisions (fs : collection.Seq [FieldInfo ], tmpVars : Map [String ,ValDef ], l: Expr [Int ]): Expr [Unit ] =
1740
+ def genReadCollisions (fs : collection.Seq [FieldInfo ], tmpVars : Map [String ,ValDef ], l: Expr [Int ])( using Quotes ) : Expr [Unit ] =
1738
1741
val s0 : Expr [Unit ] = unexpectedFieldHandler(in,l)
1739
1742
fs.foldRight(s0){ (f, acc) =>
1740
1743
val readValue : Expr [Unit ] =
@@ -1755,7 +1758,8 @@ object JsonCodecMaker {
1755
1758
' { if ($in.isCharBufEqualsTo($l, $ {Expr (f.mappedName)})) $readValue else $acc }
1756
1759
}
1757
1760
1758
- def readFieldsBlock (l : Expr [Int ]): Expr [Unit ] =
1761
+ def readFieldsBlock (l : Expr [Int ])(using Quotes ): Expr [Unit ] =
1762
+ // using Quotes for workarround agains https://github.com/lampepfl/dotty/issues/14137
1759
1763
if (readFields.size <= 8 && readFields.map(fiLength).sum <= 64 )
1760
1764
genReadCollisions(readFields, readVarsMap, l)
1761
1765
else {
0 commit comments