BigInt and other j.l.Numbers are considered AnyVals instead of AnyRefs with Typeable
sjrd opened this issue · 0 comments
sjrd commented
The following test case fails:
val n: Any = BigInt(23)
val cn = n.cast[AnyRef]
assertTrue(cn.isDefined)
val cn2 = n.cast[AnyVal]
assertTrue(cn2.isEmpty)
This is because Typeable.isValClass
uses classOf[j.l.Number].isAssignableFrom(clazz)
instead of explicitly listing the 6 boxed number classes:
shapeless/core/src/main/scala/shapeless/typeable.scala
Lines 77 to 81 in ded1d04
java.math.BigInteger
, scala.math.BigInt
and their decimal counterparts are examples of AnyRef
types that are subclasses of java.lang.Number
.