47degrees / helios

A purely functional JSON library for Kotlin built on Λrrow
https://47degrees.github.io/helios/
Apache License 2.0
169 stars 22 forks source link

Nullable type results in StackOverflowError #121

Open czterocyty opened 4 years ago

czterocyty commented 4 years ago

Hi,

We play with nullable types, eg: val a: String? inside our data class. However generated code as well as simple test snippet results in StackOverflowError:

    "Nullable String element" {
      val str: String? = "abc"

      val js: Json = NullableEncoderInstance<String>(String.encoder()).run {
        str.encode()
      }

      println(js)
    }

It looks like NullableEncoderInstance cannot see encode extension function of the enclosed encoder:

override fun A?.encode(): Json =
    this?.let { a -> encoderA().let { a.encode() } } ?: JsNull
pakoito commented 4 years ago

This looks like a shadowing error. It may be trying to get another extfun in a different context. It needs to be imported with a name such as import bla.encode as blaEncode, and then use a.blaEncode()