Skip to content

Commit

Permalink
dev: Add BigInt support
Browse files Browse the repository at this point in the history
  • Loading branch information
Iltotore committed Sep 11, 2024
1 parent 3ac1310 commit 6896bae
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion main/src/io/github/iltotore/iron/macros/ReflectUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ class ReflectUtil[Q <: Quotes & Singleton](using val _quotes: Q):

private val enhancedDecoders: Map[TypeRepr, (Term, Map[String, ?]) => Either[DecodingFailure, ?]] = Map(
TypeRepr.of[Boolean] -> decodeBoolean,
TypeRepr.of[String] -> decodeString
TypeRepr.of[BigInt] -> decodeBigInt,
TypeRepr.of[String] -> decodeString
)

/**
Expand Down Expand Up @@ -325,3 +326,11 @@ class ReflectUtil[Q <: Quotes & Singleton](using val _quotes: Q):
case (leftResult, rightResult) => Left(DecodingFailure.StringPartsNotInlined(List(leftResult, rightResult)))

case _ => Left(DecodingFailure.Unknown)

def decodeBigInt(term: Term, definitions: Map[String, ?]): Either[DecodingFailure, BigInt] =
term match
case Apply(Select(Ident("BigInt"), "apply"), List(value)) =>
if value.tpe <:< TypeRepr.of[Int] then decodeTerm[Int](value, definitions).map(BigInt.apply)
else if value.tpe <:< TypeRepr.of[Long] then decodeTerm[Long](value, definitions).map(BigInt.apply)
else Left(DecodingFailure.Unknown)
case _ => Left(DecodingFailure.Unknown)

0 comments on commit 6896bae

Please sign in to comment.