amazon-ion / ion-element-kotlin

IonElement is an immutable in-memory representation of the Ion data format. IonElement's API is idiomatic to Kotlin.
Apache License 2.0
8 stars 8 forks source link

Implement `AnyElement.bigIntegerValue` for `LongIntElementImpl` #48

Closed alancai98 closed 3 years ago

alancai98 commented 3 years ago

Currently LongIntElementImpl does not implement AnyElement.bigIntegerValue. Because of this, calling bigIntegerValue will rely on the default implementation, which throws an error.

Sample replication case:

val foo : AnyElement = loadSingleElement("${Long.MAX_VALUE}")
val bigIntValue = foo.bigIntegerValue

This results in the following error:

<unknown location>: Expected an element of type INT but found an element of type INT
com.amazon.ionelement.api.IonElementConstraintException: <unknown location>: Expected an element of type INT but found an element of type INT
    at com.amazon.ionelement.api.IonUtils.constraintError(IonUtils.kt:49)
    at com.amazon.ionelement.impl.AnyElementBase.errIfNotTyped(AnyElementBase.kt:105)
    at com.amazon.ionelement.impl.AnyElementBase.getBigIntegerValue(AnyElementBase.kt:199)

A workaround until this is fixed could be:

val bigIntValue = when(foo.integerSize) {
    IntElementSize.LONG -> BigInteger.valueOf(foo.longValue)
    IntElementSize.BIG_INTEGER -> foo.bigIntegerValue
}

Possible other TODO: